trace/fgraph: Fix error handling
authorGuenter Roeck <linux@roeck-us.net>
Sat, 6 Sep 2025 05:06:18 +0000 (22:06 -0700)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Sat, 6 Sep 2025 16:12:38 +0000 (12:12 -0400)
Commit edede7a6dcd7 ("trace/fgraph: Fix the warning caused by missing
unregister notifier") added a call to unregister the PM notifier if
register_ftrace_graph() failed. It does so unconditionally. However,
the PM notifier is only registered with the first call to
register_ftrace_graph(). If the first registration was successful and
a subsequent registration failed, the notifier is now unregistered even
if ftrace graphs are still registered.

Fix the problem by only unregistering the PM notifier during error handling
if there are no active fgraph registrations.

Fixes: edede7a6dcd7 ("trace/fgraph: Fix the warning caused by missing unregister notifier")
Closes: https://lore.kernel.org/all/63b0ba5a-a928-438e-84f9-93028dd72e54@roeck-us.net/
Cc: Ye Weihua <yeweihua4@huawei.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20250906050618.2634078-1-linux@roeck-us.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/fgraph.c

index 2a42c1036ea87c6666421d317c63bd287c6a90b4..1e3b32b1e82cd5801e163b81c682564af391e6c8 100644 (file)
@@ -1397,7 +1397,8 @@ error:
                ftrace_graph_active--;
                gops->saved_func = NULL;
                fgraph_lru_release_index(i);
-               unregister_pm_notifier(&ftrace_suspend_notifier);
+               if (!ftrace_graph_active)
+                       unregister_pm_notifier(&ftrace_suspend_notifier);
        }
        return ret;
 }