Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Avoid uninitialized use of perf_stat_config

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
91f88a0a 681f34d5

+2 -2
+1 -1
tools/perf/tests/stat.c
··· 27 27 struct machine *machine __maybe_unused) 28 28 { 29 29 struct perf_record_stat_config *config = &event->stat_config; 30 - struct perf_stat_config stat_config; 30 + struct perf_stat_config stat_config = {}; 31 31 32 32 #define HAS(term, val) \ 33 33 has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
+1 -1
tools/perf/util/stat.c
··· 729 729 730 730 size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp) 731 731 { 732 - struct perf_stat_config sc; 732 + struct perf_stat_config sc = {}; 733 733 size_t ret; 734 734 735 735 perf_event__read_stat_config(&sc, &event->stat_config);