trace: find the correct ftrace event
PATCH 1/1 trace: find the correct ftrace event
The original code doesn't work because "call" is never NULL there.
---
My code should work, but it seems like there should but it seems like there should be a more elegant way to do this?
kernel/trace/trace_events_filter.c +5 -2
@@ -1388,16 +1388,19 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,struct event_filter *filter;struct filter_parse_state *ps;struct ftrace_event_call *call =NULL ; +int found =0 ;mutex_lock (&event_mutex);list_for_each_entry (call, &ftrace_events, list) { -if (call->id == event_id) +if (call->id == event_id) { + found =1 ;break ; + } } err = -EINVAL ; -if (!call) +if (!found) goto out_unlock; err = -EEXIST ;
Steven Rostedt
maintainerQuoted 1 line · Dan Carpenter
The original code doesn't work because "call" is never NULL there.
A one line change would have done the same ;-)
Quoted 17 lines
Signed-off-by Dan Carpenter <[email protected]>---
My code should work, but it seems like there should but it seems like there should be a more elegant way to do this?kernel/trace/trace_events_filter.c +1
-0@@ -1388,16 +1388,19 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,struct event_filter *filter;struct filter_parse_state *ps;struct ftrace_event_call *call =NULL ; +int found =0 ;mutex_lock (&event_mutex);
kernel/trace/trace_events_filter.c int ftrace_profile_set_filter(struct perf_event *event, int event_id, · line 1400
Quoted 10 lines
kernel/trace/trace_events_filter.c +3
-2list_for_each_entry (call, &ftrace_events, list) { -if (call->id == event_id) +if (call->id == event_id) { + found =1 ;break ; + } } err = -EINVAL ; -if (!call)
if (call == &ftrace_events)
-- Steve
Quoted 4 lines
kernel/trace/trace_events_filter.c +1
-0+if (!found) goto out_unlock; err = -EEXIST ;
Quoted 30 lines · Steven Rostedt
Quoted 1 line · Dan Carpenter
The original code doesn't work because "call" is never NULL there.
A one line change would have done the same ;-)
Quoted 25 lines
Signed-off-by Dan Carpenter <[email protected]>---
My code should work, but it seems like there should but it seems like there should be a more elegant way to do this?kernel/trace/trace_events_filter.c +4
-1@@ -1388,16 +1388,19 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,struct event_filter *filter;struct filter_parse_state *ps;struct ftrace_event_call *call =NULL ; +int found =0 ;mutex_lock (&event_mutex);list_for_each_entry (call, &ftrace_events, list) { -if (call->id == event_id) +if (call->id == event_id) { + found =1 ;break ; + } }
Quoted 5 lines
kernel/trace/trace_events_filter.c int ftrace_profile_set_filter(struct perf_event *event, int event_id, · line 1400
Quoted 2 lines
kernel/trace/trace_events_filter.c +0
-1err = -EINVAL ; -if (!call)if (call == &ftrace_events)
Man... That makes my head hurt. It only works because ->list is the first element in the struct.
We'd need a cast.
Is that really cleaner?
regards,
dan carpenter
Quoted 13 lines
-- Steve
kernel/trace/trace_events_filter.c int ftrace_profile_set_filter(struct perf_event *event, int event_id, · line 1406
Quoted 4 lines
kernel/trace/trace_events_filter.c +1
-0+if (!found) goto out_unlock; err = -EEXIST ;--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Steven Rostedt
maintainerQuoted 26 lines · Dan Carpenter
Quoted 20 lines
Quoted 20 lines
kernel/trace/trace_events_filter.c +4
-1@@ -1388,16 +1388,19 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,struct event_filter *filter;struct filter_parse_state *ps;struct ftrace_event_call *call =NULL ; +int found =0 ;mutex_lock (&event_mutex);list_for_each_entry (call, &ftrace_events, list) { -if (call->id == event_id) +if (call->id == event_id) { + found =1 ;break ; + } }Quoted 5 lines
kernel/trace/trace_events_filter.c int ftrace_profile_set_filter(struct perf_event *event, int event_id, · line 1400
Quoted 2 lines
kernel/trace/trace_events_filter.c +0
-1err = -EINVAL ; -if (!call)if (call == &ftrace_events)
Quoted 4 lines
Man... That makes my head hurt. It only works because ->list is the first element in the struct.
We'd need a cast.
Oops, I missed the fact that it was list_*_entry(). That should be:
if (call->list != &ftrace_events)
No cast needed.
Quoted 2 lines
Is that really cleaner?
Perhaps not, but I think it is more elegant ;-)
-- Steve
Quoted 31 lines · Steven Rostedt
Quoted 29 lines · Dan Carpenter
Quoted 20 lines
Quoted 20 lines
kernel/trace/trace_events_filter.c +4
-1@@ -1388,16 +1388,19 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,struct event_filter *filter;struct filter_parse_state *ps;struct ftrace_event_call *call =NULL ; +int found =0 ;mutex_lock (&event_mutex);list_for_each_entry (call, &ftrace_events, list) { -if (call->id == event_id) +if (call->id == event_id) { + found =1 ;break ; + } }Quoted 5 lines
kernel/trace/trace_events_filter.c int ftrace_profile_set_filter(struct perf_event *event, int event_id, · line 1400
Quoted 2 lines
kernel/trace/trace_events_filter.c +0
-1err = -EINVAL ; -if (!call)if (call == &ftrace_events)Man... That makes my head hurt. It only works because ->list is the first element in the struct.
Quoted 8 lines
Quoted 1 line
We'd need a cast.
Oops, I missed the fact that it was list_*_entry(). That should be:
if (call->list != &ftrace_events)No cast needed.
Hm... "list" is a struct not a pointer to a struct.
So it would have to be:
if (&call->list == &ftrace_events)
goto out_unlock;That's how the list_for_each_entry() determines the end of the list as well.
I'll send a patch to do that.
regards,
dan carpenter
Quoted 6 lines
Quoted 2 lines
Is that really cleaner?
Perhaps not, but I think it is more elegant ;-)
-- Steve
PATCH v2 1/1 trace: find the correct ftrace event
In reply to Steven RostedtThe original code doesn't work because "call" is never NULL there.
---
The original patch was fine, but this version is more tasteful. ;)
kernel/trace/trace_events_filter.c +1 -1
@@ -1397,7 +1397,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, } err = -EINVAL ; -if (!call) +if (&call->list == &ftrace_events) goto out_unlock; err = -EEXIST ;
Steven Rostedt
maintainerQuoted 3 lines · Dan Carpenter
The original code doesn't work because "call" is never NULL there.
Signed-off-by Dan Carpenter <[email protected]>
Thanks, I'll apply and test this on Monday.
-- Steve
Quoted 17 lines
---
The original patch was fine, but this version is more tasteful. ;)kernel/trace/trace_events_filter.c +1
-1@@ -1397,7 +1397,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, } err = -EINVAL ; -if (!call) +if (&call->list == &ftrace_events) goto out_unlock; err = -EEXIST ;
[tip:perf/core] perf: Fix check at end of event search
In reply to Dan CarpenterCommit-ID: d9f599e1e6d019968b35d2dc63074b9e8964fa69 Gitweb: http://git.kernel.org/tip/d9f599e1e6d019968b35d2dc63074b9e8964fa69 Author: Dan Carpenter <[email protected]> AuthorDate: Sat, 20 Mar 2010 17:39:11 +0300 Committer: Steven Rostedt <[email protected]> CommitDate: Thu, 6 May 2010 19:49:52 -0400
perf: Fix check at end of event search
The original code doesn't work because "call" is never NULL there.
LKML-Reference: <20100320143911.GF5331@bicker>
--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +1 -1
@@ -1398,7 +1398,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, } err = -EINVAL ; -if (!call) +if (&call->list == &ftrace_events) goto out_unlock; err = -EEXIST ;