From nobody Thu Dec 18 18:47:15 2025 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) (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 2312B20E70A for ; Mon, 3 Feb 2025 18:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738607552; cv=none; b=EJpX+KYhI+FSPze5NOmjmyk8uGEaxj86NtFlphBRPtrn+kLNL1LZJnPiv3y1xiz6dsKTStc/HT7mdbQRLtdfykTEPEsg0jcLMJEQzhQt7BH9zWEO8+oxejRafyqmzpwce0ZenG5LJq76yPAqX3j1P5iI9t8Q4ki9mtXfXRDgR+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738607552; c=relaxed/simple; bh=V/SLKuz6awEKvKWxXGy1bMn2FNkDHdJBqK+p7mxM0vQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XHMkk9Jggu0mw3O/2Ow/htvSfAjxQbdsaXo/7sCZePt17XtzC8QpSmbQQAZoAoA8xFutdT5ZyA/U8ySf8rguCXsSFBtOE8GHP2On4KPpHK7mytyF50fXKPHQJVJa4mCiu3G4p0IQWa0kCIb29s739pedG4w4uebqfNRZTci0TmQ= 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=rzs/Ce4g; arc=none smtp.client-ip=91.218.175.175 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="rzs/Ce4g" 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=1738607546; 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=qNDGXaXWlDnWYxdojyVit6ndHU1GueE33oD7T19VC2c=; b=rzs/Ce4g0oaSYJyETez0mm4OJwtlje8EWZyFWbqrmmbuIhFwOioB8YKEVrrRV2vQ2zzhvZ 2FHlzTz26XW4ED0qT33C9yjcIPwAcn7nvqcBwLyEY5IDq8WHkZLPqq9tvbmIWwNz9BwPsj iFlPkb5MKZBwJT3TqUtgW/DANaei9b0= 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 , Janne Grunau Subject: [PATCH v2 09/14] KVM: arm64: Use guard() to cleanup usage of arm_pmus_lock Date: Mon, 3 Feb 2025 10:31:06 -0800 Message-Id: <20250203183111.191519-10-oliver.upton@linux.dev> In-Reply-To: <20250203183111.191519-1-oliver.upton@linux.dev> References: <20250203183111.191519-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. Tested-by: Janne Grunau 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 8413a038e6c2..3048e22c240b 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -802,26 +802,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 @@ -842,17 +839,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