perf tools: Move dereference after NULL test
authorJulia Lawall <julia@diku.dk>
Sat, 17 Oct 2009 06:43:17 +0000 (08:43 +0200)
committerIngo Molnar <mingo@elte.hu>
Sat, 17 Oct 2009 07:29:10 +0000 (09:29 +0200)
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>

Signed-off-by: Julia Lawall <julia@diku.dk>
LKML-Reference: <Pine.LNX.4.64.0910170842500.9213@ask.diku.dk>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-annotate.c
tools/perf/builtin-report.c
tools/perf/builtin-sched.c
tools/perf/builtin-trace.c

index 3fe0de03004d72a454ad92e95c1578e5b9422a58..56ba71658d70a49425a29bde6d8a9166f16f4b84 100644 (file)
@@ -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);
index 015c79745966970a812a0d6c0088d9d45a886dbb..a4f8cc20915138250c288787205dd23f4b187cbb 100644 (file)
@@ -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;
 
index c9c68563e964e6fd5e9bbd836743ce16d3d445a9..57ad3f458ef58a45fce40467c0a9df429679fe23 100644 (file)
@@ -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;
 
index ce8459ac28457fd6b995ce33edd17596683a8a6a..4c129ff0bb162c10d7256c56253078b56b99998d 100644 (file)
@@ -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;