From nobody Sat Feb 7 08:10:56 2026 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7589020A5FA for ; Tue, 3 Dec 2024 19:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733254401; cv=none; b=e/64CxmmQXAfRC8C8RVFgWxkbDBzr6obOLTCSqqs1EEMRFvmHd1qfuC5tucuetbQ4UWHNFjYD8qWDH+IIRavl5vBV5KeuuNMs0cN0xtCbFMYerjensVHPzj4xMvhhXvYMGdF/FVc7AtYN3EZUyyAsgsHkC+MCpmfjlz9O2YCup0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733254401; c=relaxed/simple; bh=mqycjLHJskfq5KD1jGg3uIo+Pk1OVodsj2K+Bn99v8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hEdpQJ/imLxPkkDp/eSpT0OnXKLmMzF/o5+yOybEARATGdtYyuvJyrnokCJfTqzkmg4cXzwd8qDs0lU22XBNO8M/KTDaVqvIdPAHsx2mFryDwjGDrLjbBYq+rmhn+J2CFDKLBCF4zzSrfAoKdVDukEWhJ/1zliiSH+CQjxnNaZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=WddZkFB2; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="WddZkFB2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1733254397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5U1Fan/QcV2LlUTdRSrRaXaLGxdimJKYM/ndFwGiWng=; b=WddZkFB2IqhFulg1mRqqL6Bon7Cxp9zhYJ76iO/rjCdsiHSgBUHWp0sMkaiBV6jKelP0Ao ZAxC703WOTt85SZXL4PtiY8dD7BMWhPFaTn/oCGw+cNn5/ARaa7lvUGlEjHNnex2kKpfk1 P+bBlO0VogXV3ajV4ehsMBE/Il8iwY4= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: Marc Zyngier , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mingwei Zhang , Colton Lewis , Raghavendra Rao Ananta , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Oliver Upton Subject: [RFC PATCH 09/14] KVM: arm64: Use guard() to cleanup usage of arm_pmus_lock Date: Tue, 3 Dec 2024 11:32:15 -0800 Message-Id: <20241203193220.1070811-10-oliver.upton@linux.dev> In-Reply-To: <20241203193220.1070811-1-oliver.upton@linux.dev> References: <20241203193220.1070811-1-oliver.upton@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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 --- arch/arm64/kvm/pmu-emul.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 1ff343d43b61..b9756a0d054a 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -819,26 +819,23 @@ void kvm_host_pmu_init(struct arm_pmu *pmu) if (!pmuv3_implemented(kvm_arm_pmu_get_pmuver_limit())) return; =20 - mutex_lock(&arm_pmus_lock); + guard(mutex)(&arm_pmus_lock); =20 entry =3D kmalloc(sizeof(*entry), GFP_KERNEL); if (!entry) - goto out_unlock; + return; =20 entry->arm_pmu =3D pmu; list_add_tail(&entry->entry, &arm_pmus); - -out_unlock: - mutex_unlock(&arm_pmus_lock); } =20 static struct arm_pmu *kvm_pmu_probe_armpmu(void) { - struct arm_pmu *tmp, *pmu =3D NULL; struct arm_pmu_entry *entry; + struct arm_pmu *pmu; int cpu; =20 - mutex_lock(&arm_pmus_lock); + guard(mutex)(&arm_pmus_lock); =20 /* * It is safe to use a stale cpu to iterate the list of PMUs so long as @@ -859,17 +856,13 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) */ cpu =3D raw_smp_processor_id(); list_for_each_entry(entry, &arm_pmus, entry) { - tmp =3D entry->arm_pmu; + pmu =3D entry->arm_pmu; =20 - if (cpumask_test_cpu(cpu, &tmp->supported_cpus)) { - pmu =3D tmp; - break; - } + if (cpumask_test_cpu(cpu, &pmu->supported_cpus)) + return pmu; } =20 - mutex_unlock(&arm_pmus_lock); - - return pmu; + return NULL; } =20 static u64 __compute_pmceid(struct arm_pmu *pmu, bool pmceid1) --=20 2.39.5