Skip to content

Commit 1432afb

Browse files
committed
ftrace: Use guard to lock ftrace_lock in cache_mod()
The ftrace_lock is held throughout cache_mod(), use guard to simplify the error paths. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 06294cf commit 1432afb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

kernel/trace/ftrace.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4947,14 +4947,14 @@ static int cache_mod(struct trace_array *tr,
49474947
{
49484948
struct ftrace_mod_load *ftrace_mod, *n;
49494949
struct list_head *head = enable ? &tr->mod_trace : &tr->mod_notrace;
4950-
int ret;
49514950

4952-
mutex_lock(&ftrace_lock);
4951+
guard(mutex)(&ftrace_lock);
49534952

49544953
/* We do not cache inverse filters */
49554954
if (func[0] == '!') {
4955+
int ret = -EINVAL;
4956+
49564957
func++;
4957-
ret = -EINVAL;
49584958

49594959
/* Look to remove this hash */
49604960
list_for_each_entry_safe(ftrace_mod, n, head, list) {
@@ -4970,20 +4970,15 @@ static int cache_mod(struct trace_array *tr,
49704970
continue;
49714971
}
49724972
}
4973-
goto out;
4973+
return ret;
49744974
}
49754975

4976-
ret = -EINVAL;
49774976
/* We only care about modules that have not been loaded yet */
49784977
if (module_exists(module))
4979-
goto out;
4978+
return -EINVAL;
49804979

49814980
/* Save this string off, and execute it when the module is loaded */
4982-
ret = ftrace_add_mod(tr, func, module, enable);
4983-
out:
4984-
mutex_unlock(&ftrace_lock);
4985-
4986-
return ret;
4981+
return ftrace_add_mod(tr, func, module, enable);
49874982
}
49884983

49894984
static int

0 commit comments

Comments
 (0)