tools/perf: Move dereference after NULL test
Subsystems (2)
PATCH 14/14 tools/perf: Move dereference after NULL test
From: Julia Lawall <[email protected]>
In each case, if the NULL test on thread is needed, then the dereference should be after the NULL test.
A simplified version of the semantic match that detects this problem is as follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x = NULL
// </smpl>
--- tools/perf/builtin-annotate.c | 4 ++-- tools/perf/builtin-report.c | 4 ++-- tools/perf/builtin-sched.c | 4 ++-- tools/perf/builtin-trace.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
tools/perf/builtin-sched.c +2 -2
@@ -1581,14 +1581,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) (void *)(long )ip, (long long)period); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread =NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +process_raw_event (event, more_data, cpu, timestamp, thread);return 0 ;
tools/perf/builtin-report.c +2 -2
@@ -634,14 +634,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) } } -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread =NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (comm_list && !strlist__has_entry (comm_list, thread->comm))return 0 ;
tools/perf/builtin-annotate.c +2 -2
@@ -110,14 +110,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) event->ip.pid, (void *)(long)ip); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread =NULL ) {fprintf (stderr,"problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (event->header.misc &PERF_RECORD_MISC_KERNEL ) { level ='k' ; sym =kernel_maps__find_symbol (ip, &map);
tools/perf/builtin-trace.c +2 -2
@@ -87,14 +87,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) (void *)(long)ip, (long long)period); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread =NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (sample_type &PERF_SAMPLE_RAW ) {struct {u32 size;
[tip:perf/core] perf tools: Move dereference after NULL test
Commit-ID: f39cdf25bf77219676ec5360980ac40b1a7e144a Gitweb: http://git.kernel.org/tip/f39cdf25bf77219676ec5360980ac40b1a7e144a Author: Julia Lawall <[email protected]> AuthorDate: Sat, 17 Oct 2009 08:43:17 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 17 Oct 2009 09:29:10 +0200
perf tools: Move dereference after NULL test
In each case, if the NULL test on thread is needed, then the dereference should be after the NULL test.
A simplified version of the semantic match that detects this problem is as follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 4 ++-- tools/perf/builtin-report.c | 4 ++-- tools/perf/builtin-sched.c | 4 ++-- tools/perf/builtin-trace.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
tools/perf/builtin-annotate.c +2 -2
@@ -104,14 +104,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) event->ip.pid, (void *)(long)ip); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread ==NULL ) {fprintf (stderr,"problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (event->header.misc &PERF_RECORD_MISC_KERNEL ) { level ='k' ; sym =kernel_maps__find_symbol (ip, &map);
tools/perf/builtin-report.c +2 -2
@@ -629,14 +629,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) } } -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread ==NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (comm_list && !strlist__has_entry (comm_list, thread->comm))return 0 ;
tools/perf/builtin-sched.c +2 -2
@@ -1667,14 +1667,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) (void *)(long )ip, (long long)period); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread ==NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (profile_cpu !=-1 && profile_cpu != (int ) cpu)return 0 ;
tools/perf/builtin-trace.c +2 -2
@@ -80,14 +80,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) (void *)(long)ip, (long long)period); -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); -if (thread ==NULL ) {eprintf ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +if (sample_type &PERF_SAMPLE_RAW ) {struct {u32 size;