Skip to content

Commit

Permalink
fgraph: Fix missing unlock in register_ftrace_graph()
Browse files Browse the repository at this point in the history
Use guard(mutex)() to acquire and automatically release ftrace_lock,
fixing the issue of not unlocking when calling cpuhp_setup_state()
fails.

Fixes smatch warning:

kernel/trace/fgraph.c:1317 register_ftrace_graph() warn: inconsistent returns '&ftrace_lock'.

Link: https://lore.kernel.org/20241024155917.1019580-1-lihuafei1@huawei.com
Fixes: 2c02f73 ("fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202410220121.wxg0olfd-lkp@intel.com/
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Li Huafei <lihuafei1@huawei.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
Li Huafei authored and Steven Rostedt (Google) committed Oct 25, 2024
1 parent fae4078 commit bd3734d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions kernel/trace/fgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
int ret = 0;
int i = -1;

mutex_lock(&ftrace_lock);
guard(mutex)(&ftrace_lock);

if (!fgraph_initialized) {
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init",
Expand All @@ -1273,10 +1273,8 @@ int register_ftrace_graph(struct fgraph_ops *gops)
}

i = fgraph_lru_alloc_index();
if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub)) {
ret = -ENOSPC;
goto out;
}
if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub))
return -ENOSPC;
gops->idx = i;

ftrace_graph_active++;
Expand Down Expand Up @@ -1313,8 +1311,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
gops->saved_func = NULL;
fgraph_lru_release_index(i);
}
out:
mutex_unlock(&ftrace_lock);
return ret;
}

Expand Down

0 comments on commit bd3734d

Please sign in to comment.