Skip to content

Commit df62db5

Browse files
committed
tracing: Allocate the snapshot buffer before enabling probe
Currently the snapshot trigger enables the probe and then allocates the snapshot. If the probe triggers before the allocation, it could cause the snapshot to fail and turn tracing off. It's best to allocate the snapshot buffer first, and then enable the trigger. If something goes wrong in the enabling of the trigger, the snapshot buffer is still allocated, but it can also be freed by the user by writting zero into the snapshot buffer file. Also add a check of the return status of alloc_snapshot(). Cc: [email protected] Fixes: 77fd5c1 ("tracing: Add snapshot trigger to function probes") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 9ed19c7 commit df62db5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

kernel/trace/trace.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6733,11 +6733,13 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
67336733
return ret;
67346734

67356735
out_reg:
6736-
ret = register_ftrace_function_probe(glob, ops, count);
6736+
ret = alloc_snapshot(&global_trace);
6737+
if (ret < 0)
6738+
goto out;
67376739

6738-
if (ret >= 0)
6739-
alloc_snapshot(&global_trace);
6740+
ret = register_ftrace_function_probe(glob, ops, count);
67406741

6742+
out:
67416743
return ret < 0 ? ret : 0;
67426744
}
67436745

0 commit comments

Comments
 (0)