From fdaab6393155ad2c73fc2b2ab621cc1756dc051d Mon Sep 17 00:00:00 2001 From: Li Huafei Date: Thu, 24 Oct 2024 23:59:17 +0800 Subject: [PATCH] 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 Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202410220121.wxg0olfd-lkp@intel.com/ Suggested-by: Steven Rostedt Signed-off-by: Li Huafei Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin Signed-off-by: Manuel Diewald Signed-off-by: Stefan Bader --- kernel/trace/fgraph.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index cdcaf7ddd68d..5e060c78fbfb 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -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; }