Skip to content

Commit a09a5aa

Browse files
Li Qianggroeck
authored andcommitted
hwmon: (cgbc-hwmon) Add missing NULL check after devm_kzalloc()
The driver allocates memory for sensor data using devm_kzalloc(), but did not check if the allocation succeeded. In case of memory allocation failure, dereferencing the NULL pointer would lead to a kernel crash. Add a NULL pointer check and return -ENOMEM to handle allocation failure properly. Signed-off-by: Li Qiang <[email protected]> Fixes: 08ebc9d ("hwmon: Add Congatec Board Controller monitoring driver") Reviewed-by: Thomas Richard <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 57f6f47 commit a09a5aa

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/hwmon/cgbc-hwmon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ static int cgbc_hwmon_probe_sensors(struct device *dev, struct cgbc_hwmon_data *
107107
nb_sensors = data[0];
108108

109109
hwmon->sensors = devm_kzalloc(dev, sizeof(*hwmon->sensors) * nb_sensors, GFP_KERNEL);
110+
if (!hwmon->sensors)
111+
return -ENOMEM;
112+
110113
sensor = hwmon->sensors;
111114

112115
for (i = 0; i < nb_sensors; i++) {

0 commit comments

Comments
 (0)