Skip to content

Commit 62878b4

Browse files
captain5050namhyung
authored andcommitted
perf hwmon_pmu: Ensure hwmon key union is zeroed before use
Non-zero values led to mismatches in testing. This was reproducible with -fsanitize=undefined. Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org> Closes: https://lore.kernel.org/lkml/Zzdtj0PEWEX3ATwL@x1/ Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20241119230033.115369-1-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 870748f commit 62878b4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/perf/util/hwmon_pmu.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
274274
int number;
275275
enum hwmon_item item;
276276
bool alarm;
277-
union hwmon_pmu_event_key key = {};
277+
union hwmon_pmu_event_key key = { .type_and_num = 0 };
278278
struct hwmon_pmu_event_value *value;
279279

280280
if (ent->d_type != DT_REG)
@@ -560,7 +560,7 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
560560
struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
561561
enum hwmon_type type;
562562
int number;
563-
union hwmon_pmu_event_key key = {};
563+
union hwmon_pmu_event_key key = { .type_and_num = 0 };
564564
struct hashmap_entry *cur;
565565
size_t bkt;
566566

@@ -623,10 +623,11 @@ static int hwmon_pmu__config_term(const struct hwmon_pmu *hwm,
623623
return -EINVAL;
624624
} else {
625625
union hwmon_pmu_event_key key = {
626-
.type = type,
627-
.num = number,
626+
.type_and_num = 0,
628627
};
629628

629+
key.type = type;
630+
key.num = number;
630631
attr->config = key.type_and_num;
631632
}
632633
return 0;

0 commit comments

Comments
 (0)