]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ftrace: Use guard to lock ftrace_lock in cache_mod()
authorSteven Rostedt <rostedt@goodmis.org>
Mon, 28 Oct 2024 07:12:31 +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 held throughout cache_mod(), use guard to simplify the
error 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.088458856@goodmis.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index 44adc34643c9f13aad0c2f4282fea964dad71eb5..64997416415ec1ccd1efa8996cfb24f3f77257b3 100644 (file)
@@ -4947,14 +4947,14 @@ static int cache_mod(struct trace_array *tr,
 {
        struct ftrace_mod_load *ftrace_mod, *n;
        struct list_head *head = enable ? &tr->mod_trace : &tr->mod_notrace;
-       int ret;
 
-       mutex_lock(&ftrace_lock);
+       guard(mutex)(&ftrace_lock);
 
        /* We do not cache inverse filters */
        if (func[0] == '!') {
+               int ret = -EINVAL;
+
                func++;
-               ret = -EINVAL;
 
                /* Look to remove this hash */
                list_for_each_entry_safe(ftrace_mod, n, head, list) {
@@ -4970,20 +4970,15 @@ static int cache_mod(struct trace_array *tr,
                                continue;
                        }
                }
-               goto out;
+               return ret;
        }
 
-       ret = -EINVAL;
        /* We only care about modules that have not been loaded yet */
        if (module_exists(module))
-               goto out;
+               return -EINVAL;
 
        /* Save this string off, and execute it when the module is loaded */
-       ret = ftrace_add_mod(tr, func, module, enable);
- out:
-       mutex_unlock(&ftrace_lock);
-
-       return ret;
+       return ftrace_add_mod(tr, func, module, enable);
 }
 
 static int