mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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 <j@jannau.net> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250305202641.428114-8-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
This commit is contained in:
@@ -790,26 +790,23 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
|
||||
if (!pmuv3_implemented(kvm_arm_pmu_get_pmuver_limit()))
|
||||
return;
|
||||
|
||||
mutex_lock(&arm_pmus_lock);
|
||||
guard(mutex)(&arm_pmus_lock);
|
||||
|
||||
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
|
||||
if (!entry)
|
||||
goto out_unlock;
|
||||
return;
|
||||
|
||||
entry->arm_pmu = pmu;
|
||||
list_add_tail(&entry->entry, &arm_pmus);
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&arm_pmus_lock);
|
||||
}
|
||||
|
||||
static struct arm_pmu *kvm_pmu_probe_armpmu(void)
|
||||
{
|
||||
struct arm_pmu *tmp, *pmu = NULL;
|
||||
struct arm_pmu_entry *entry;
|
||||
struct arm_pmu *pmu;
|
||||
int cpu;
|
||||
|
||||
mutex_lock(&arm_pmus_lock);
|
||||
guard(mutex)(&arm_pmus_lock);
|
||||
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
cpu = raw_smp_processor_id();
|
||||
list_for_each_entry(entry, &arm_pmus, entry) {
|
||||
tmp = entry->arm_pmu;
|
||||
pmu = entry->arm_pmu;
|
||||
|
||||
if (cpumask_test_cpu(cpu, &tmp->supported_cpus)) {
|
||||
pmu = tmp;
|
||||
break;
|
||||
}
|
||||
if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
|
||||
return pmu;
|
||||
}
|
||||
|
||||
mutex_unlock(&arm_pmus_lock);
|
||||
|
||||
return pmu;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u64 __compute_pmceid(struct arm_pmu *pmu, bool pmceid1)
|
||||
|
||||
Reference in New Issue
Block a user