Skip to content

Commit

Permalink
tracing: Allocate the snapshot buffer before enabling probe
Browse files Browse the repository at this point in the history
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: stable@vger.kernel.org
Fixes: 77fd5c1 ("tracing: Add snapshot trigger to function probes")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Apr 19, 2017
1 parent 9ed19c7 commit df62db5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6733,11 +6733,13 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
return ret;

out_reg:
ret = register_ftrace_function_probe(glob, ops, count);
ret = alloc_snapshot(&global_trace);
if (ret < 0)
goto out;

if (ret >= 0)
alloc_snapshot(&global_trace);
ret = register_ftrace_function_probe(glob, ops, count);

out:
return ret < 0 ? ret : 0;
}

Expand Down

0 comments on commit df62db5

Please sign in to comment.