Skip to content

Commit a34d023

Browse files
linuswgregkh
authored andcommitted
hwmon: Deal with errors from the thermal subsystem
commit 47c332d upstream. If the thermal subsystem returne -EPROBE_DEFER or any other error when hwmon calls devm_thermal_zone_of_sensor_register(), this is silently ignored. I ran into this with an incorrectly defined thermal zone, making it non-existing and thus this call failed with -EPROBE_DEFER assuming it would appear later. The sensor was still added which is incorrect: sensors must strictly be added after the thermal zones, so deferred probe must be respected. Fixes: d560168 ("hwmon: (core) New hwmon registration API") Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cb4412e commit a34d023

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/hwmon/hwmon.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static int hwmon_thermal_add_sensor(struct device *dev,
143143
struct hwmon_device *hwdev, int index)
144144
{
145145
struct hwmon_thermal_data *tdata;
146+
struct thermal_zone_device *tzd;
146147

147148
tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL);
148149
if (!tdata)
@@ -151,8 +152,14 @@ static int hwmon_thermal_add_sensor(struct device *dev,
151152
tdata->hwdev = hwdev;
152153
tdata->index = index;
153154

154-
devm_thermal_zone_of_sensor_register(&hwdev->dev, index, tdata,
155-
&hwmon_thermal_ops);
155+
tzd = devm_thermal_zone_of_sensor_register(&hwdev->dev, index, tdata,
156+
&hwmon_thermal_ops);
157+
/*
158+
* If CONFIG_THERMAL_OF is disabled, this returns -ENODEV,
159+
* so ignore that error but forward any other error.
160+
*/
161+
if (IS_ERR(tzd) && (PTR_ERR(tzd) != -ENODEV))
162+
return PTR_ERR(tzd);
156163

157164
return 0;
158165
}
@@ -586,14 +593,20 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
586593
if (!chip->ops->is_visible(drvdata, hwmon_temp,
587594
hwmon_temp_input, j))
588595
continue;
589-
if (info[i]->config[j] & HWMON_T_INPUT)
590-
hwmon_thermal_add_sensor(dev, hwdev, j);
596+
if (info[i]->config[j] & HWMON_T_INPUT) {
597+
err = hwmon_thermal_add_sensor(dev,
598+
hwdev, j);
599+
if (err)
600+
goto free_device;
601+
}
591602
}
592603
}
593604
}
594605

595606
return hdev;
596607

608+
free_device:
609+
device_unregister(hdev);
597610
free_hwmon:
598611
kfree(hwdev);
599612
ida_remove:

0 commit comments

Comments
 (0)