From: Peter Zijlstra <peterz@infradead.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 5/5] ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash()
Date: Mon, 28 Oct 2024 10:16:56 +0100 [thread overview]
Message-ID: <20241028091656.GJ9767@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241028071308.406073025@goodmis.org>
On Mon, Oct 28, 2024 at 03:12:33AM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> 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.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> 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, char *buffer)
>
> func_g.len = strlen(func_g.search);
>
> - mutex_lock(&ftrace_lock);
> + guard(mutex)(&ftrace_lock);
>
> - if (unlikely(ftrace_disabled)) {
> - mutex_unlock(&ftrace_lock);
> + if (unlikely(ftrace_disabled))
> return -ENODEV;
> - }
>
> do_for_each_ftrace_rec(pg, rec) {
>
> @@ -6837,7 +6835,7 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
> if (entry)
> continue;
> if (add_hash_entry(hash, rec->ip) == 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);
>
> - if (fail)
> - return -EINVAL;
> -
> - return 0;
> + return fail ? -EINVAL : 0;
> }
Isn't the fail case more a case of -ESRCH / -ENOENT rather than -EINVAL?
Anyway, that's orthogonal, the patch preserves existing semantics and
looks okay (as do the others fwiw).
next prev parent reply other threads:[~2024-10-28 9:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 7:12 [PATCH 0/5] ftrace: Use guard to take ftrace_lock Steven Rostedt
2024-10-28 7:12 ` [PATCH 1/5] fgraph: Use guard(mutex)(&ftrace_lock) for unregister_ftrace_graph() Steven Rostedt
2024-10-28 7:12 ` [PATCH 2/5] ftrace: Use guard for match_records() Steven Rostedt
2024-10-28 7:12 ` [PATCH 3/5] ftrace: Use guard to lock ftrace_lock in cache_mod() Steven Rostedt
2024-10-28 7:12 ` [PATCH 4/5] ftrace: Use guard to take the ftrace_lock in release_probe() Steven Rostedt
2024-10-28 7:12 ` [PATCH 5/5] ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash() Steven Rostedt
2024-10-28 9:16 ` Peter Zijlstra [this message]
2024-10-28 14:18 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241028091656.GJ9767@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).