Skip to content

Commit 683c0d0

Browse files
author
Herton R. Krzesinski
committed
Merge: hwmon: Handle failure to register sensor with thermal zone correctly
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1665 If devm_thermal_zone_of_sensor_register() returns -ENODEV, report that the sensor was not attached to a thermal zone but continue to register the hwmon device. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122394 Upstream Status: git@gitlab.com:redhat/centos-stream/src/kernel/centos-stream-9.git Signed-off-by: David Marlin <dmarlin@redhat.com> ## Scratch Brew build https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=49249631 ## Description If an attempt is made to a sensor with a thermal zone and it fails, the call to devm_thermal_zone_of_sensor_register() may return -ENODEV. This can result in a crash (NULL pointer dereference). The hwmon core needs to handle all errors returned from calls to devm_thermal_zone_of_sensor_register(). If the call fails with -ENODEV, report that the sensor was not attached to a thermal zone but continue to register the hwmon device. Approved-by: Mark Langsdorf <mlangsdo@redhat.com> Approved-by: Dean Nelson <dnelson@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 3fecdf4 + 00f2391 commit 683c0d0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/hwmon/hwmon.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index)
214214

215215
tzd = devm_thermal_zone_of_sensor_register(dev, index, tdata,
216216
&hwmon_thermal_ops);
217-
/*
218-
* If CONFIG_THERMAL_OF is disabled, this returns -ENODEV,
219-
* so ignore that error but forward any other error.
220-
*/
221-
if (IS_ERR(tzd) && (PTR_ERR(tzd) != -ENODEV))
222-
return PTR_ERR(tzd);
217+
if (IS_ERR(tzd)) {
218+
if (PTR_ERR(tzd) != -ENODEV)
219+
return PTR_ERR(tzd);
220+
dev_info(dev, "temp%d_input not attached to any thermal zone\n",
221+
index + 1);
222+
devm_kfree(dev, tdata);
223+
return 0;
224+
}
223225

224226
err = devm_add_action(dev, hwmon_thermal_remove_sensor, &tdata->node);
225227
if (err)

0 commit comments

Comments
 (0)