thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference
Zhang Rui
reviewerPATCH v2 1/1 thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference
When the hwmon device node of a thermal zone device is not found, using hwmon->device causes a kernel NULL pointer dereference.
Skip removing hwmon device for thermal zones without hwmon device, and fix the kernel NULL pointer dereference when hwmon device is not found.
---
v1 -> v2
Add check for devices without hwmon device.
Use pr_debug instead of dev_dbg.
--- drivers/thermal/thermal_hwmon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/thermal/thermal_hwmon.c +4 -2
@@ -226,10 +226,12 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)struct thermal_hwmon_device *hwmon;struct thermal_hwmon_temp *temp; +if (tz->tzp && tz->tzp->no_hwmon) +return ; + hwmon =thermal_hwmon_lookup_by_type (tz);if (unlikely (!hwmon)) { -/* Should never happen... */ -dev_dbg (hwmon->device,"hwmon device lookup failed!\n" ); +pr_debug ("hwmon device lookup failed!\n" );return ; }
Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerQuoted 9 lines · Zhang Rui
When the hwmon device node of a thermal zone device is not found, using
hwmon->devicecauses a kernel NULL pointer dereference.Skip removing hwmon device for thermal zones without hwmon device, and fix the kernel NULL pointer dereference when hwmon device is not found.
Fixes dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field")Reported-by Preble Adam C <[email protected]>
Do you have a link to the bug report? I'm wondering where exactly it triggers.
Quoted 29 lines
Signed-off-by Zhang Rui <[email protected]>---
v1 -> v2
Add check for devices without hwmon device.
Usepr_debuginstead ofdev_dbg.--- drivers/thermal/thermal_hwmon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/thermal/thermal_hwmon.c +4
-3@@ -226,10 +226,12 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)struct thermal_hwmon_device *hwmon;struct thermal_hwmon_temp *temp; +if (tz->tzp && tz->tzp->no_hwmon) +return ; + hwmon =thermal_hwmon_lookup_by_type (tz);if (unlikely (!hwmon)) { -/* Should never happen... */ -dev_dbg (hwmon->device,"hwmon device lookup failed!\n" ); +pr_debug ("hwmon device lookup failed!\n" );return ; } --