Skip to contentSkip to conversation

trace: find the correct ftrace event

PATCH Superseded Dan Carpenter 2 participants 8 messages Mar 20, 2010 – May 7, 2010 Tracing

lore
Share & tools
lore
#0 lore raw

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
index 4615f62..6070c70 100644
@@ -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;
maintainer
#1 lore raw
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 17 lines

---
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
index 4615f62..6070c70 100644
@@ -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 -2
 	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 (call == &ftrace_events)

-- Steve

Quoted 4 lines
kernel/trace/trace_events_filter.c +1 -0
+	if (!found)
 		goto out_unlock;
 
 	err = -EEXIST;
#2 lore raw
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

---
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
index 4615f62..6070c70 100644
@@ -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 -1
 	err = -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/

maintainer
#3 lore raw
Quoted 26 lines · Dan Carpenter
Quoted 20 lines
Quoted 20 lines
kernel/trace/trace_events_filter.c +4 -1
index 4615f62..6070c70 100644
@@ -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 -1
 	err = -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

#4 lore raw
Quoted 31 lines · Steven Rostedt
Quoted 29 lines · Dan Carpenter
Quoted 20 lines
Quoted 20 lines
kernel/trace/trace_events_filter.c +4 -1
index 4615f62..6070c70 100644
@@ -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 -1
 	err = -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

#5 lore raw

PATCH v2 1/1 trace: find the correct ftrace event

In reply to Steven Rostedt

The 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
index 4615f62..c1a263a 100644
@@ -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;
maintainer
#6 lore raw
Quoted 3 lines · Dan Carpenter

The original code doesn't work because "call" is never NULL there.

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
index 4615f62..c1a263a 100644
@@ -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;
#7 lore raw

[tip:perf/core] perf: Fix check at end of event search

In reply to Dan Carpenter
Commit-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
index 88c0b6d..58092d8 100644
@@ -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;