Skip to content

Commit beacbc6

Browse files
committed
Merge tag 'hwmon-for-linus-v4.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fix from Guenter Roeck: "Handle errors from thermal subsystem" * tag 'hwmon-for-linus-v4.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: Deal with errors from the thermal subsystem
2 parents e2a9300 + 47c332d commit beacbc6

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)