From nobody Mon Nov 25 12:19:58 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 8BB32191493; Mon, 28 Oct 2024 07:12:19 +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=1730099539; cv=none; b=jDIH41p8Rn8BBWt9s94ncSsytZRmGIf6reSQ+1Bmd5t6Iz7wnvuvGLz/twR1O7IFt/K9cA19YDBv+M7QbEkhCi/UTflZGn6QOGr2DC4XFZPCh689DEDm+Lj3DKWTqO62Zd8SwWoDnw6sxxs8XxT590hCdknlBx3VqBexmuks2jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=CrpZfsQvl+o/WpkUnkpWR88txNPc6znh+Atzuyb7wlw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=icU7R4tSwt0s7wNmmv8SB55jkFSKwkvYSLt+kXMWNgxWP/aGWNTCz0i7MvwFMVOSpIPAoIqrxM5hgLv6MLINSYi5if16sUWdEhfKyDrWYh92Yiy3ogxVuKpw6gZe0vt8rHBp2HZWHpFxPqcvchdtqeACgXgtQkHi8FdJzOFzOSw= 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 37328C4CEE3; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw4-000000053DY-0HWJ; Mon, 28 Oct 2024 03:13:08 -0400 Message-ID: <20241028071307.927146604@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:30 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 2/5] ftrace: Use guard for match_records() References: <20241028071228.575900713@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 held for most of match_records() until the end of the function. Use guard to make error paths simpler. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index e9fd4fb2769e..44adc34643c9 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4829,15 +4829,13 @@ match_records(struct ftrace_hash *hash, char *func,= int len, char *mod) mod_g.len =3D strlen(mod_g.search); } =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 if (unlikely(ftrace_disabled)) - goto out_unlock; + return 0; =20 - if (func_g.type =3D=3D MATCH_INDEX) { - found =3D add_rec_by_index(hash, &func_g, clear_filter); - goto out_unlock; - } + if (func_g.type =3D=3D MATCH_INDEX) + return add_rec_by_index(hash, &func_g, clear_filter); =20 do_for_each_ftrace_rec(pg, rec) { =20 @@ -4846,16 +4844,12 @@ match_records(struct ftrace_hash *hash, char *func,= int len, char *mod) =20 if (ftrace_match_record(rec, &func_g, mod_match, exclude_mod)) { ret =3D enter_record(hash, rec, clear_filter); - if (ret < 0) { - found =3D ret; - goto out_unlock; - } + if (ret < 0) + return ret; found =3D 1; } cond_resched(); } while_for_each_ftrace_rec(); - out_unlock: - mutex_unlock(&ftrace_lock); =20 return found; } --=20 2.45.2