Skip to content

Commit 28aa197

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 9d7c6d0 commit 28aa197

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
@@ -802,26 +802,23 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
802802
if (!pmuv3_implemented(kvm_arm_pmu_get_pmuver_limit()))
803803
return;
804804

805-
mutex_lock(&arm_pmus_lock);
805+
guard(mutex)(&arm_pmus_lock);
806806

807807
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
808808
if (!entry)
809-
goto out_unlock;
809+
return;
810810

811811
entry->arm_pmu = pmu;
812812
list_add_tail(&entry->entry, &arm_pmus);
813-
814-
out_unlock:
815-
mutex_unlock(&arm_pmus_lock);
816813
}
817814

818815
static struct arm_pmu *kvm_pmu_probe_armpmu(void)
819816
{
820-
struct arm_pmu *tmp, *pmu = NULL;
821817
struct arm_pmu_entry *entry;
818+
struct arm_pmu *pmu;
822819
int cpu;
823820

824-
mutex_lock(&arm_pmus_lock);
821+
guard(mutex)(&arm_pmus_lock);
825822

826823
/*
827824
* It is safe to use a stale cpu to iterate the list of PMUs so long as
@@ -842,17 +839,13 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void)
842839
*/
843840
cpu = raw_smp_processor_id();
844841
list_for_each_entry(entry, &arm_pmus, entry) {
845-
tmp = entry->arm_pmu;
842+
pmu = entry->arm_pmu;
846843

847-
if (cpumask_test_cpu(cpu, &tmp->supported_cpus)) {
848-
pmu = tmp;
849-
break;
850-
}
844+
if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
845+
return pmu;
851846
}
852847

853-
mutex_unlock(&arm_pmus_lock);
854-
855-
return pmu;
848+
return NULL;
856849
}
857850

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

0 commit comments

Comments
 (0)