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

perf mem-events: Avoid uninitialized read

pmu should be initialized to NULL before perf_pmus__scan loop. Fix and
shrink the scope of pmu at the same time. Issue detected by clang-tidy.

Fixes: 5752c20f3787 ("perf mem: Scan all PMUs instead of just core ones")
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: llvm@lists.linux.dev
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20231009183920.200859-10-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
85f73c37 b3aa09ee

+2 -1
+2 -1
tools/perf/util/mem-events.c
··· 185 185 { 186 186 int i = *argv_nr, k = 0; 187 187 struct perf_mem_event *e; 188 - struct perf_pmu *pmu; 189 188 190 189 for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) { 191 190 e = perf_mem_events__ptr(j); ··· 201 202 rec_argv[i++] = "-e"; 202 203 rec_argv[i++] = perf_mem_events__name(j, NULL); 203 204 } else { 205 + struct perf_pmu *pmu = NULL; 206 + 204 207 if (!e->supported) { 205 208 perf_mem_events__print_unsupport_hybrid(e, j); 206 209 return -1;