Re: [PATCH 1/3] perfcounter: Initialize tracepoint record beforeany use

From: Frederic Weisbecker
Date: Fri Aug 07 2009 - 22:30:51 EST


On Sat, Aug 08, 2009 at 04:26:35AM +0200, Frederic Weisbecker wrote:
> 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@xxxxxxx>
> Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Mike Galbraith <efault@xxxxxx>
> Cc: Paul Mackerras <paulus@xxxxxxxxx>
> ---


Hmm, sorry I've resent the perf tools series by mistake. Please
ignore the [PATCH */4] "perf tools: *" series that has already been
sent.

The only ones are [PATCH */3] perfcounter: *

Thanks.


> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/