]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash()
authorSteven Rostedt <rostedt@goodmis.org>
Mon, 28 Oct 2024 07:12:33 +0000 (03:12 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 29 Oct 2024 11:43:02 +0000 (07:43 -0400)
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 <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/20241028071308.406073025@goodmis.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index c0fabd7da5b20a15dad23448e55bafe375698b26..b4ef469f4fd207f94713baadeb6f5f3da329679b 100644 (file)
@@ -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;
 }
 
 static ssize_t