From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0E3A73A4F2F for ; Mon, 30 Mar 2026 14:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774880750; cv=none; b=OKaRJS7Qn2RkTeUranAmAGhR8aRkQ7roEkHgkOOp03MrknCjPF29GCfFbODpdUpRYCQlqBNwza+16ZKc0F4gIYBb+4VfGE5gW7HVdpNfkVwoAKcU4alC2Y5485UP04gyTVjvU6AYKN5bEhVOcmg1N3UEUbWG7FxpGx4CYHHC124= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774880750; c=relaxed/simple; bh=FVdN53PEOBh1Ao2ZKs9Iksqpbj744xmpIBrAgKm7Ljs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rYtYJyA3sdNtALcicVTYkQ8CCzkMdn+RexvdL9Su9+8psNxSzRq2UT8nIjkFL4hfK3HKueQoYt/7OU9zlVXJ3p9N6GEKBkXRIQ4xz8ucSv/d4KZdXXUMJNOwDCRmtCRpRszpALUoOjBQNVQ+wBARfJX3zyKxkNEA56Cg6vGM2YY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O3FhXf6E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O3FhXf6E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4570C4CEF7; Mon, 30 Mar 2026 14:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774880749; bh=FVdN53PEOBh1Ao2ZKs9Iksqpbj744xmpIBrAgKm7Ljs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O3FhXf6ENwX1NgU01DOkwUUuUO/ap27uebgp2kHbprcoc3oTIyB3gFuh2p/HreljF Tv5cj7bV6CFOouTbx+iVS6VlzK/KA21wy67XIM57qQ78t2409q0aljXOBv7c1IrIVl vrNthvNonHo2neUroY0norSJmK4PtuFeeYYHAAzPuj9o1RVKthVHR3ycHvU4Yq9xdb 7huE7NmmfyIAm1hKQ+x1+xkCsh5B7xLlYmsJ4FTkzLNgcIIbXdda86sIiQojAHhcER QhKwwufwV3EwRXrETOx/PKjKSmHa7oBhurEkFlDyhR6Hofc4JosMDxhF6x/+YvfZQu 0fPq83I4RAdWQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Sasha Levin Subject: [PATCH 6.6.y 1/2] tracing: Switch trace_osnoise.c code over to use guard() and __free() Date: Mon, 30 Mar 2026 10:25:46 -0400 Message-ID: <20260330142547.819699-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026032953-garnet-dropout-ed0f@gregkh> References: <2026032953-garnet-dropout-ed0f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Steven Rostedt [ Upstream commit 930d2b32c0af6895ba4c6ca6404e7f7b6dc214ed ] The osnoise_hotplug_workfn() grabs two mutexes and cpu_read_lock(). It has various gotos to handle unlocking them. Switch them over to guard() and let the compiler worry about it. The osnoise_cpus_read() has a temporary mask_str allocated and there's some gotos to make sure it gets freed on error paths. Switch that over to __free() to let the compiler worry about it. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Peter Zijlstra Link: https://lore.kernel.org/20241225222931.517329690@goodmis.org Signed-off-by: Steven Rostedt (Google) Stable-dep-of: 1f9885732248 ("tracing: Fix potential deadlock in cpu hotplug with osnoise") Signed-off-by: Sasha Levin --- kernel/trace/trace_osnoise.c | 40 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 4d12d02965a4b..6bf8d18a15b7c 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2099,26 +2099,21 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy) { unsigned int cpu = smp_processor_id(); - mutex_lock(&trace_types_lock); + guard(mutex)(&trace_types_lock); if (!osnoise_has_registered_instances()) - goto out_unlock_trace; + return; - mutex_lock(&interface_lock); - cpus_read_lock(); + guard(mutex)(&interface_lock); + guard(cpus_read_lock)(); if (!cpu_online(cpu)) - goto out_unlock; + return; + if (!cpumask_test_cpu(cpu, &osnoise_cpumask)) - goto out_unlock; + return; start_kthread(cpu); - -out_unlock: - cpus_read_unlock(); - mutex_unlock(&interface_lock); -out_unlock_trace: - mutex_unlock(&trace_types_lock); } static DECLARE_WORK(osnoise_hotplug_work, osnoise_hotplug_workfn); @@ -2316,31 +2311,22 @@ static ssize_t osnoise_cpus_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos) { - char *mask_str; + char *mask_str __free(kfree) = NULL; int len; - mutex_lock(&interface_lock); + guard(mutex)(&interface_lock); len = snprintf(NULL, 0, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask)) + 1; mask_str = kmalloc(len, GFP_KERNEL); - if (!mask_str) { - count = -ENOMEM; - goto out_unlock; - } + if (!mask_str) + return -ENOMEM; len = snprintf(mask_str, len, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask)); - if (len >= count) { - count = -EINVAL; - goto out_free; - } + if (len >= count) + return -EINVAL; count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len); -out_free: - kfree(mask_str); -out_unlock: - mutex_unlock(&interface_lock); - return count; } -- 2.53.0