lkml.org 
[lkml]   [2009]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/3] perfcounter: Initialize tracepoint record before any use
Date
Despite that the tracepoint record is always present when the
PERF_SAMPLE_TP_RECORD flag is set, gcc whines, thinking it might not
be initialized:

kernel/perf_counter.c: In function ‘perf_counter_output’:
kernel/perf_counter.c:2650: warning: ‘tp’ may be used uninitialized in this function

Then, initialize it to NULL and always check if it's not NULL before
dereference it.

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
---
kernel/perf_counter.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 142ae5a..a6963e2 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -2647,7 +2647,7 @@ void perf_counter_output(struct perf_counter *counter, int nmi,
u64 counter;
} group_entry;
struct perf_callchain_entry *callchain = NULL;
- struct perf_tracepoint_record *tp;
+ struct perf_tracepoint_record *tp = NULL;
int callchain_size = 0;
u64 time;
struct {
@@ -2718,7 +2718,8 @@ void perf_counter_output(struct perf_counter *counter, int nmi,

if (sample_type & PERF_SAMPLE_TP_RECORD) {
tp = data->private;
- header.size += tp->size;
+ if (tp)
+ header.size += tp->size;
}

ret = perf_output_begin(&handle, counter, header.size, nmi, 1);
@@ -2784,7 +2785,7 @@ void perf_counter_output(struct perf_counter *counter, int nmi,
}
}

- if (sample_type & PERF_SAMPLE_TP_RECORD)
+ if ((sample_type & PERF_SAMPLE_TP_RECORD) && tp)
perf_output_copy(&handle, tp->record, tp->size);

perf_output_end(&handle);
--
1.6.2.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-08-08 04:29    [W:0.120 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site