fgraph: Fix missing unlock in register_ftrace_graph()
BugLink: https://bugs.launchpad.net/bugs/2097575 [ Upstream commit bd3734db86e01e20dd239a40b419059a0ce9c901 ] 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: 2c02f7375e65 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
This commit is contained in:
@@ -637,7 +637,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
|
||||
static bool fgraph_initialized;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&ftrace_lock);
|
||||
guard(mutex)(&ftrace_lock);
|
||||
|
||||
if (!fgraph_initialized) {
|
||||
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init",
|
||||
@@ -651,10 +651,8 @@ int register_ftrace_graph(struct fgraph_ops *gops)
|
||||
}
|
||||
|
||||
/* we currently allow only one tracer registered at a time */
|
||||
if (ftrace_graph_active) {
|
||||
ret = -EBUSY;
|
||||
goto out;
|
||||
}
|
||||
if (ftrace_graph_active)
|
||||
return -EBUSY;
|
||||
|
||||
register_pm_notifier(&ftrace_suspend_notifier);
|
||||
|
||||
@@ -662,7 +660,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
|
||||
ret = start_graph_tracing();
|
||||
if (ret) {
|
||||
ftrace_graph_active--;
|
||||
goto out;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ftrace_graph_return = gops->retfunc;
|
||||
@@ -678,8 +676,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
|
||||
update_function_graph_func();
|
||||
|
||||
ret = ftrace_startup(&graph_ops, FTRACE_START_FUNC_RET);
|
||||
out:
|
||||
mutex_unlock(&ftrace_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user