Skip to content

Commit 47c332d

Browse files
linuswgroeck
authored andcommitted
hwmon: Deal with errors from the thermal subsystem
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 <linus.walleij@linaro.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 464e1d5 commit 47c332d

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
}
@@ -621,14 +628,20 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
621628
if (!chip->ops->is_visible(drvdata, hwmon_temp,
622629
hwmon_temp_input, j))
623630
continue;
624-
if (info[i]->config[j] & HWMON_T_INPUT)
625-
hwmon_thermal_add_sensor(dev, hwdev, j);
631+
if (info[i]->config[j] & HWMON_T_INPUT) {
632+
err = hwmon_thermal_add_sensor(dev,
633+
hwdev, j);
634+
if (err)
635+
goto free_device;
636+
}
626637
}
627638
}
628639
}
629640

630641
return hdev;
631642

643+
free_device:
644+
device_unregister(hdev);
632645
free_hwmon:
633646
kfree(hwdev);
634647
ida_remove:

0 commit comments

Comments
 (0)