Skip to content

Commit 218d372

Browse files
committed
fgraph: Keep track of when fgraph_ops are registered or not
Add a warning if unregister_ftrace_graph() is called without ever registering it, or if register_ftrace_graph() is called twice. This can detect errors when they happen and not later when there's a side effect: Link: https://lore.kernel.org/all/[email protected]/ Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Mark Rutland <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 437889b commit 218d372

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

kernel/trace/fgraph.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,10 @@ int register_ftrace_graph(struct fgraph_ops *gops)
13251325
int ret = 0;
13261326
int i = -1;
13271327

1328+
if (WARN_ONCE(gops->ops.flags & FTRACE_OPS_FL_GRAPH,
1329+
"function graph ops registered again"))
1330+
return -EBUSY;
1331+
13281332
guard(mutex)(&ftrace_lock);
13291333

13301334
if (!fgraph_stack_cachep) {
@@ -1401,17 +1405,21 @@ void unregister_ftrace_graph(struct fgraph_ops *gops)
14011405
{
14021406
int command = 0;
14031407

1408+
if (WARN_ONCE(!(gops->ops.flags & FTRACE_OPS_FL_GRAPH),
1409+
"function graph ops unregistered without registering"))
1410+
return;
1411+
14041412
guard(mutex)(&ftrace_lock);
14051413

14061414
if (unlikely(!ftrace_graph_active))
1407-
return;
1415+
goto out;
14081416

14091417
if (unlikely(gops->idx < 0 || gops->idx >= FGRAPH_ARRAY_SIZE ||
14101418
fgraph_array[gops->idx] != gops))
1411-
return;
1419+
goto out;
14121420

14131421
if (fgraph_lru_release_index(gops->idx) < 0)
1414-
return;
1422+
goto out;
14151423

14161424
fgraph_array[gops->idx] = &fgraph_stub;
14171425

@@ -1434,4 +1442,6 @@ void unregister_ftrace_graph(struct fgraph_ops *gops)
14341442
unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
14351443
}
14361444
gops->saved_func = NULL;
1445+
out:
1446+
gops->ops.flags &= ~FTRACE_OPS_FL_GRAPH;
14371447
}

0 commit comments

Comments
 (0)