From nobody Mon Nov 25 07:35:42 2024 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 711151CF7C3 for ; Wed, 30 Oct 2024 05:36:12 +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=1730266572; cv=none; b=eea9ift1sFNfe90sAQrliiX1AGBjtGu4pB8yGlqi1llzdSHsZQPlP19L99ZQP38jRYgWFBvyV/fy/Q9KNn2jdtFrifB6zFgHtI8Oai8K5uEDO1WeNSmUegMzik7hHtl/A/ammNmXf+CVlnWpJI24DitxI/j3l4J6ZJcUx4eW+Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=QuMj2j7J2Ycw9ms4XdQMDgXZ6XGNcGjJq/4L8I63wTo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nhObgNm+xVLvDfqnvuW5gWMC59o5Rf6diHyvtlWvh/wSGq+yspPJD9xAI04bPws53uWaUEz5CvKbJlWRKe8UrsOYfGIfRMF8PSGoTWtzXd0aNgeRGvCm0hcqY0+z9nMp+9uAK4cvKz5w+msWBqyWfBtdzPi5bNAYeE8c4X1mCHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54C8FC4CEED; Wed, 30 Oct 2024 05:36:12 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BFa-30L7; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053705.580984615@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 7/7] ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash() References: <20241030053650.956861738@goodmis.org> 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 Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is taken for most of the ftrace_graph_set_hash() function throughout the end. Use guard to take the ftrace_lock to simplify the exit paths. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071308.406073025@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c0fabd7da5b2..b4ef469f4fd2 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6816,12 +6816,10 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, cha= r *buffer) =20 func_g.len =3D strlen(func_g.search); =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 - if (unlikely(ftrace_disabled)) { - mutex_unlock(&ftrace_lock); + if (unlikely(ftrace_disabled)) return -ENODEV; - } =20 do_for_each_ftrace_rec(pg, rec) { =20 @@ -6837,7 +6835,7 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char = *buffer) if (entry) continue; if (add_hash_entry(hash, rec->ip) =3D=3D NULL) - goto out; + return 0; } else { if (entry) { free_hash_entry(hash, entry); @@ -6846,13 +6844,8 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char= *buffer) } } } while_for_each_ftrace_rec(); -out: - mutex_unlock(&ftrace_lock); =20 - if (fail) - return -EINVAL; - - return 0; + return fail ? -EINVAL : 0; } =20 static ssize_t --=20 2.45.2