]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
perf hwmon_pmu: Ensure hwmon key union is zeroed before use
authorIan Rogers <irogers@google.com>
Tue, 19 Nov 2024 23:00:33 +0000 (15:00 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 22 Nov 2024 21:38:39 +0000 (13:38 -0800)
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>
tools/perf/util/hwmon_pmu.c

index ac2245acdc6d95dae5654486113dadf9253c5013..4d9d6f4054342f9328832e8884b8253d944608df 100644 (file)
@@ -274,7 +274,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
                int number;
                enum hwmon_item item;
                bool alarm;
-               union hwmon_pmu_event_key key = {};
+               union hwmon_pmu_event_key key = { .type_and_num = 0 };
                struct hwmon_pmu_event_value *value;
 
                if (ent->d_type != DT_REG)
@@ -560,7 +560,7 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
        struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
        enum hwmon_type type;
        int number;
-       union hwmon_pmu_event_key key = {};
+       union hwmon_pmu_event_key key = { .type_and_num = 0 };
        struct hashmap_entry *cur;
        size_t bkt;
 
@@ -623,10 +623,11 @@ static int hwmon_pmu__config_term(const struct hwmon_pmu *hwm,
                                        return -EINVAL;
                        } else {
                                union hwmon_pmu_event_key key = {
-                                       .type = type,
-                                       .num = number,
+                                       .type_and_num = 0,
                                };
 
+                               key.type = type;
+                               key.num = number;
                                attr->config = key.type_and_num;
                        }
                        return 0;