tracing/kprobes: Simplify the logic of enable_trace_kprobe()
Steven Rostedt
maintainerPATCH 1/1 tracing/kprobes: Simplify the logic of enable_trace_kprobe()
[ Note this is applied on top of the other patch to quiet gcc ]
From: "Steven Rostedt (VMware)" <[email protected]>
The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.
--- kernel/trace/trace_kprobe.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
kernel/trace/trace_kprobe.c +24 -18
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,return NULL ; } +static inline int enable_probe (struct trace_kprobe *tk) +{ +int ret =0 ; + +if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { +if (trace_kprobe_is_return (tk)) + ret =enable_kretprobe (&tk->rp); +else + ret =enable_kprobe (&tk->rp.kp); + } + +return ret; +} +/* * Enable trace_probe * if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { -struct event_file_link *link =NULL ; +struct event_file_link *link;int ret =0 ;if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)list_add_tail_rcu (&link->list, &tk->tp.files); tk->tp.flags |=TP_FLAG_TRACE ; - }else - tk->tp.flags |=TP_FLAG_PROFILE ; - -if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { -if (trace_kprobe_is_return (tk)) - ret =enable_kretprobe (&tk->rp); -else - ret =enable_kprobe (&tk->rp.kp); - } - -if (ret) { -if (file) { -/* Notice the if is true on not WARN() */ -if (!WARN_ON_ONCE (!link)) -list_del_rcu (&link->list); + ret =enable_probe (tk); +if (ret) { +list_del_rcu (&link->list);kfree (link); tk->tp.flags &= ~TP_FLAG_TRACE ; - }else { - tk->tp.flags &= ~TP_FLAG_PROFILE ; } + + }else { + tk->tp.flags |=TP_FLAG_PROFILE ; + ret =enable_probe (tk); +if (ret) + tk->tp.flags &= ~TP_FLAG_PROFILE ; } out:return ret;
Signature · 1 line
2.13.6
Quoted 5 lines · Steven Rostedt
[ Note this is applied on top of the other patch to quiet gcc ]
From: "Steven Rostedt (VMware)" <[email protected]>
Quoted 8 lines
The function
enable_trace_kprobe()performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.Signed-off-by Steven Rostedt (VMware) <[email protected]>
The enable_probe() name is a bit confusing, since it's not clear what the difference is between enable_probe() and enable_trace_kprobe() without looking at the code.
Maybe call it __enable_trace_kprobe()?
Otherwise it's a definite improvement.
Signature · 1 line
Josh
Steven Rostedt
maintainerQuoted 11 lines · On Thu, 26 Jul 2018 11:43:52 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 10 lines · Steven Rostedt
[ Note this is applied on top of the other patch to quiet gcc ]
From: "Steven Rostedt (VMware)" <[email protected]>
The function
enable_trace_kprobe()performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Steven Rostedt (VMware) <[email protected]>The
enable_probe()name is a bit confusing, since it's not clear what the difference is betweenenable_probe()andenable_trace_kprobe()without looking at the code.
Yeah, I didn't like that name either.
Quoted 2 lines
Maybe call it
__enable_trace_kprobe()?
Hmm, that may work.
Quoted 5 lines
Otherwise it's a definite improvement.
Reviewed-by Josh Poimboeuf <[email protected]>
Thanks,
-- Steve
Quoted 13 lines · On Thu, 26 Jul 2018 11:43:52 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 12 lines · Steven Rostedt
[ Note this is applied on top of the other patch to quiet gcc ]
From: "Steven Rostedt (VMware)" <[email protected]>
The function
enable_trace_kprobe()performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.
Quoted 7 lines
Quoted 1 line
Signed-off-by Steven Rostedt (VMware) <[email protected]>The
enable_probe()name is a bit confusing, since it's not clear what the difference is betweenenable_probe()andenable_trace_kprobe()without looking at the code.Maybe call it
__enable_trace_kprobe()?
+1, I this this is better.
With that function name change,
Thanks!
Quoted 7 lines
Otherwise it's a definite improvement.
Reviewed-by Josh Poimboeuf <[email protected]>Signature · 1 line
Josh
Signature · 1 line
Masami Hiramatsu <[email protected]>
Steven Rostedt
maintainerPATCH v2 1/1 tracing/kprobes: Simplify the logic of enable_trace_kprobe()
From: "Steven Rostedt (VMware)" <[email protected]>
The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.
--- kernel/trace/trace_kprobe.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
kernel/trace/trace_kprobe.c +24 -18
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,return NULL ; } +static inline int __enable_trace_kprobe (struct trace_kprobe *tk) +{ +int ret =0 ; + +if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { +if (trace_kprobe_is_return (tk)) + ret =enable_kretprobe (&tk->rp); +else + ret =enable_kprobe (&tk->rp.kp); + } + +return ret; +} +/* * Enable trace_probe * if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { -struct event_file_link *link =NULL ; +struct event_file_link *link;int ret =0 ;if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)list_add_tail_rcu (&link->list, &tk->tp.files); tk->tp.flags |=TP_FLAG_TRACE ; - }else - tk->tp.flags |=TP_FLAG_PROFILE ; - -if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { -if (trace_kprobe_is_return (tk)) - ret =enable_kretprobe (&tk->rp); -else - ret =enable_kprobe (&tk->rp.kp); - } - -if (ret) { -if (file) { -/* Notice the if is true on not WARN() */ -if (!WARN_ON_ONCE (!link)) -list_del_rcu (&link->list); + ret =__enable_trace_kprobe (tk); +if (ret) { +list_del_rcu (&link->list);kfree (link); tk->tp.flags &= ~TP_FLAG_TRACE ; - }else { - tk->tp.flags &= ~TP_FLAG_PROFILE ; } + + }else { + tk->tp.flags |=TP_FLAG_PROFILE ; + ret =__enable_trace_kprobe (tk); +if (ret) + tk->tp.flags &= ~TP_FLAG_PROFILE ; } out:return ret;
Signature · 1 line
2.13.6