perf stat: Avoid uninitialized use of perf_stat_config
authorIan Rogers <irogers@google.com>
Mon, 24 Jul 2023 20:12:44 +0000 (13:12 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Jul 2023 21:23:18 +0000 (18:23 -0300)
perf_event__read_stat_config will assign values based on number of
tags and tag values. Initialize the structs to zero before they are
assigned so that no uninitialized values can be seen.

This potential error was reported by GCC with LTO enabled.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Carsten Haitzler <carsten.haitzler@arm.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Tom Rix <trix@redhat.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: bpf@vger.kernel.org
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20230724201247.748146-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/stat.c
tools/perf/util/stat.c

index 500974040fe31150823ca164e2fd8f8a44de08c6..706780fb56951182ca95c9fb6ddda1d002341cf3 100644 (file)
@@ -27,7 +27,7 @@ static int process_stat_config_event(struct perf_tool *tool __maybe_unused,
                                     struct machine *machine __maybe_unused)
 {
        struct perf_record_stat_config *config = &event->stat_config;
-       struct perf_stat_config stat_config;
+       struct perf_stat_config stat_config = {};
 
 #define HAS(term, val) \
        has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
index 967e583392c71d505a2cdf6dc10e03ab190ea435..ec350604221736783df773d40e1ea66bb6983283 100644 (file)
@@ -729,7 +729,7 @@ size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp)
 
 size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp)
 {
-       struct perf_stat_config sc;
+       struct perf_stat_config sc = {};
        size_t ret;
 
        perf_event__read_stat_config(&sc, &event->stat_config);