Skip to content

Commit bd3734d

Browse files
Li Huafeirostedt
authored andcommitted
fgraph: Fix missing unlock in register_ftrace_graph()
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>
1 parent fae4078 commit bd3734d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

kernel/trace/fgraph.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
12521252
int ret = 0;
12531253
int i = -1;
12541254

1255-
mutex_lock(&ftrace_lock);
1255+
guard(mutex)(&ftrace_lock);
12561256

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

12751275
i = fgraph_lru_alloc_index();
1276-
if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub)) {
1277-
ret = -ENOSPC;
1278-
goto out;
1279-
}
1276+
if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub))
1277+
return -ENOSPC;
12801278
gops->idx = i;
12811279

12821280
ftrace_graph_active++;
@@ -1313,8 +1311,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
13131311
gops->saved_func = NULL;
13141312
fgraph_lru_release_index(i);
13151313
}
1316-
out:
1317-
mutex_unlock(&ftrace_lock);
13181314
return ret;
13191315
}
13201316

0 commit comments

Comments
 (0)