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: 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>

authored by Li Huafei and committed by Steven Rostedt (Google) bd3734db fae4078c

Changed files
+3 -7
kernel
trace
+3 -7
kernel/trace/fgraph.c
··· 1252 1252 int ret = 0; 1253 1253 int i = -1; 1254 1254 1255 - mutex_lock(&ftrace_lock); 1255 + guard(mutex)(&ftrace_lock); 1256 1256 1257 1257 if (!fgraph_initialized) { 1258 1258 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init", ··· 1273 1273 } 1274 1274 1275 1275 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; 1280 1278 gops->idx = i; 1281 1279 1282 1280 ftrace_graph_active++; ··· 1311 1313 gops->saved_func = NULL; 1312 1314 fgraph_lru_release_index(i); 1313 1315 } 1314 - out: 1315 - mutex_unlock(&ftrace_lock); 1316 1316 return ret; 1317 1317 } 1318 1318