Skip to content

Commit 3d6d917

Browse files
committed
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. Tested-by: Janne Grunau <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent a38b67d commit 3d6d917

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

arch/arm64/kvm/pmu-emul.c

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

793-
mutex_lock(&arm_pmus_lock);
793+
guard(mutex)(&arm_pmus_lock);
794794

795795
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
796796
if (!entry)
797-
goto out_unlock;
797+
return;
798798

799799
entry->arm_pmu = pmu;
800800
list_add_tail(&entry->entry, &arm_pmus);
801-
802-
out_unlock:
803-
mutex_unlock(&arm_pmus_lock);
804801
}
805802

806803
static struct arm_pmu *kvm_pmu_probe_armpmu(void)
807804
{
808-
struct arm_pmu *tmp, *pmu = NULL;
809805
struct arm_pmu_entry *entry;
806+
struct arm_pmu *pmu;
810807
int cpu;
811808

812-
mutex_lock(&arm_pmus_lock);
809+
guard(mutex)(&arm_pmus_lock);
813810

814811
/*
815812
* It is safe to use a stale cpu to iterate the list of PMUs so long as
@@ -830,17 +827,13 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void)
830827
*/
831828
cpu = raw_smp_processor_id();
832829
list_for_each_entry(entry, &arm_pmus, entry) {
833-
tmp = entry->arm_pmu;
830+
pmu = entry->arm_pmu;
834831

835-
if (cpumask_test_cpu(cpu, &tmp->supported_cpus)) {
836-
pmu = tmp;
837-
break;
838-
}
832+
if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
833+
return pmu;
839834
}
840835

841-
mutex_unlock(&arm_pmus_lock);
842-
843-
return pmu;
836+
return NULL;
844837
}
845838

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

0 commit comments

Comments
 (0)