Commit 3d6d9172 authored by Oliver Upton's avatar Oliver Upton
Browse files

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: default avatarJanne Grunau <j@jannau.net>
Reviewed-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20250305202641.428114-8-oliver.upton@linux.dev


Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent a38b67d1
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -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)