Skip to content

Commit 48eaf64

Browse files
ouptonjannau
authored andcommitted
KVM: arm64: Use guard() to cleanup usage of arm_pmus_lock
Get rid of some goto label patterns by using guard() to drop the arm_pmus_lock when returning from a function. Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 8263209 commit 48eaf64

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

arch/arm64/kvm/pmu-emul.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -717,26 +717,23 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
717717
if (!pmuv3_implemented(kvm_arm_pmu_get_pmuver_limit()))
718718
return;
719719

720-
mutex_lock(&arm_pmus_lock);
720+
guard(mutex)(&arm_pmus_lock);
721721

722722
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
723723
if (!entry)
724-
goto out_unlock;
724+
return;
725725

726726
entry->arm_pmu = pmu;
727727
list_add_tail(&entry->entry, &arm_pmus);
728-
729-
out_unlock:
730-
mutex_unlock(&arm_pmus_lock);
731728
}
732729

733730
static struct arm_pmu *kvm_pmu_probe_armpmu(void)
734731
{
735-
struct arm_pmu *tmp, *pmu = NULL;
736732
struct arm_pmu_entry *entry;
733+
struct arm_pmu *pmu;
737734
int cpu;
738735

739-
mutex_lock(&arm_pmus_lock);
736+
guard(mutex)(&arm_pmus_lock);
740737

741738
/*
742739
* It is safe to use a stale cpu to iterate the list of PMUs so long as
@@ -757,17 +754,13 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void)
757754
*/
758755
cpu = raw_smp_processor_id();
759756
list_for_each_entry(entry, &arm_pmus, entry) {
760-
tmp = entry->arm_pmu;
757+
pmu = entry->arm_pmu;
761758

762-
if (cpumask_test_cpu(cpu, &tmp->supported_cpus)) {
763-
pmu = tmp;
764-
break;
765-
}
759+
if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
760+
return pmu;
766761
}
767762

768-
mutex_unlock(&arm_pmus_lock);
769-
770-
return pmu;
763+
return NULL;
771764
}
772765

773766
static u64 __compute_pmceid(struct arm_pmu *pmu, bool pmceid1)

0 commit comments

Comments
 (0)