diff options
| author | Li Qiang <liqiang01@kylinos.cn> | 2025-10-17 14:34:14 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-10-29 14:10:27 +0100 |
| commit | 240b82b86a091c1aa49d951d4467425420a081a0 (patch) | |
| tree | 298e37abf52fa14420c8c613616df5c64f9281b4 /drivers | |
| parent | f957c0f9975d9314b3c054ad5e4f6badd2eacc14 (diff) | |
| download | linux-240b82b86a091c1aa49d951d4467425420a081a0.tar.gz linux-240b82b86a091c1aa49d951d4467425420a081a0.tar.bz2 linux-240b82b86a091c1aa49d951d4467425420a081a0.zip | |
hwmon: (cgbc-hwmon) Add missing NULL check after devm_kzalloc()
[ Upstream commit a09a5aa8bf258ddc99a22c30f17fe304b96b5350 ]
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 <liqiang01@kylinos.cn>
Fixes: 08ebc9def79fc ("hwmon: Add Congatec Board Controller monitoring driver")
Reviewed-by: Thomas Richard <thomas.richard@bootlin.com>
Link: https://lore.kernel.org/r/20251017063414.1557447-1-liqiang01@kylinos.cn
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/hwmon/cgbc-hwmon.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/hwmon/cgbc-hwmon.c b/drivers/hwmon/cgbc-hwmon.c index 772f44d56ccf..3aff4e092132 100644 --- a/drivers/hwmon/cgbc-hwmon.c +++ b/drivers/hwmon/cgbc-hwmon.c @@ -107,6 +107,9 @@ static int cgbc_hwmon_probe_sensors(struct device *dev, struct cgbc_hwmon_data * nb_sensors = data[0]; hwmon->sensors = devm_kzalloc(dev, sizeof(*hwmon->sensors) * nb_sensors, GFP_KERNEL); + if (!hwmon->sensors) + return -ENOMEM; + sensor = hwmon->sensors; for (i = 0; i < nb_sensors; i++) { |
