Skip to content

Commit 84e2615

Browse files
darcarigroeck
authored andcommitted
hwmon: (amd_energy) fix allocation of hwmon_channel_info config
hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero. Fixes: 8abee95 ("hwmon: Add amd_energy driver to report energy counters") Signed-off-by: David Arcari <[email protected]> Cc: Naveen Krishna Chatradhi <[email protected]> Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: David Arcari <[email protected]> Acked-by: Naveen Krishna Chatradhi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 1eda523 commit 84e2615

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/hwmon/amd_energy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
222222
*/
223223
cpus = num_present_cpus() / num_siblings;
224224

225-
s_config = devm_kcalloc(dev, cpus + sockets,
225+
s_config = devm_kcalloc(dev, cpus + sockets + 1,
226226
sizeof(u32), GFP_KERNEL);
227227
if (!s_config)
228228
return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
254254
scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
255255
}
256256

257+
s_config[i] = 0;
257258
return 0;
258259
}
259260

0 commit comments

Comments
 (0)