If the devicetree node is not referenced in a zone under /thermal-zones,
devm_thermal_of_zone_register will fail with -ENODEV.
Since the driver is now also registering as an IIO device[0], allow the
probe to continue without the thermal zone.
We also can't use gadc_thermal_get_temp anymore because we haven't
necessarily initialized tz_dev.
[0] commit 3762f5851ac5 ("thermal/drivers/thermal-generic-adc: Add temperature sensor channel")
Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
---
drivers/thermal/thermal-generic-adc.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index 7c844589b153..4852e584468b 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -86,14 +86,16 @@ static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct gadc_thermal_info *gtinfo = iio_priv(indio_dev);
+ int iio_val;
int ret;
switch (mask) {
case IIO_CHAN_INFO_PROCESSED:
- ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
- if (ret)
+ ret = iio_read_channel_processed(gtinfo->channel, &iio_val);
+ if (ret < 0)
return ret;
+ *val = gadc_thermal_adc_to_temp(gtinfo, iio_val);
return IIO_VAL_INT;
default:
@@ -197,14 +199,14 @@ static int gadc_thermal_probe(struct platform_device *pdev)
&gadc_thermal_ops);
if (IS_ERR(gti->tz_dev)) {
ret = PTR_ERR(gti->tz_dev);
- if (ret != -EPROBE_DEFER)
- dev_err(dev,
- "Thermal zone sensor register failed: %d\n",
- ret);
- return ret;
- }
+ if (ret == -EPROBE_DEFER)
+ return ret;
- devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
+ dev_info(dev, "Thermal zone sensor register failed: %d\n",
+ ret);
+ } else {
+ devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
+ }
return gadc_iio_register(&pdev->dev, gti);
}
--
2.53.0
On Fri, Feb 20, 2026 at 10:19:07AM +0100, Luca Weiss wrote:
> If the devicetree node is not referenced in a zone under /thermal-zones,
> devm_thermal_of_zone_register will fail with -ENODEV.
devm_thermal_of_zone_register()
> Since the driver is now also registering as an IIO device[0], allow the
> probe to continue without the thermal zone.
Isn't it dangerous?
> We also can't use gadc_thermal_get_temp anymore because we haven't
gadc_thermal_get_temp()
> necessarily initialized tz_dev.
> [0] commit 3762f5851ac5 ("thermal/drivers/thermal-generic-adc: Add temperature sensor channel")
You can make it a Link tag:
Link: https://git.kernel.org/torvalds/c/3762f5851ac5 [0]
> Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
...
> if (IS_ERR(gti->tz_dev)) {
> ret = PTR_ERR(gti->tz_dev);
> - if (ret != -EPROBE_DEFER)
> - dev_err(dev,
> - "Thermal zone sensor register failed: %d\n",
> - ret);
> - return ret;
> - }
> + if (ret == -EPROBE_DEFER)
> + return ret;
I believe it's better to return all possible errors. If you see the
similarities with regulator APIs, then use an explicit check for -ENODEV.
> - devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
> + dev_info(dev, "Thermal zone sensor register failed: %d\n",
> + ret);
> + } else {
> + devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
> + }
--
With Best Regards,
Andy Shevchenko
On Fri Feb 20, 2026 at 11:50 AM CET, Andy Shevchenko wrote:
> On Fri, Feb 20, 2026 at 10:19:07AM +0100, Luca Weiss wrote:
>> If the devicetree node is not referenced in a zone under /thermal-zones,
>> devm_thermal_of_zone_register will fail with -ENODEV.
>
> devm_thermal_of_zone_register()
Ack
>
>> Since the driver is now also registering as an IIO device[0], allow the
>> probe to continue without the thermal zone.
>
> Isn't it dangerous?
Why? The idea is that generic-adc-thermal is the middleman to convert
from one IIO input to one IIO output, and is purely informational, so
that user space can get some temperature value to display somewhere.
How thermal management will be hooked up in the future to charger
drivers is a bit out of scope here I'd say. There's not even any cooling
support in the power supply core anymore, that was ripped out a while
ago if I'm not mistaken.
>
>> We also can't use gadc_thermal_get_temp anymore because we haven't
>
> gadc_thermal_get_temp()
Ack
>
>> necessarily initialized tz_dev.
>
>> [0] commit 3762f5851ac5 ("thermal/drivers/thermal-generic-adc: Add temperature sensor channel")
>
> You can make it a Link tag:
>
> Link: https://git.kernel.org/torvalds/c/3762f5851ac5 [0]
Ack
>
>> Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
>
> ...
>
>> if (IS_ERR(gti->tz_dev)) {
>> ret = PTR_ERR(gti->tz_dev);
>> - if (ret != -EPROBE_DEFER)
>> - dev_err(dev,
>> - "Thermal zone sensor register failed: %d\n",
>> - ret);
>> - return ret;
>> - }
>> + if (ret == -EPROBE_DEFER)
>> + return ret;
>
> I believe it's better to return all possible errors. If you see the
> similarities with regulator APIs, then use an explicit check for -ENODEV.
Sure, will update this.
Regards
Luca
>
>> - devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
>> + dev_info(dev, "Thermal zone sensor register failed: %d\n",
>> + ret);
>> + } else {
>> + devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
>> + }
On Fri, Feb 20, 2026 at 12:31:36PM +0100, Luca Weiss wrote: > On Fri Feb 20, 2026 at 11:50 AM CET, Andy Shevchenko wrote: > > On Fri, Feb 20, 2026 at 10:19:07AM +0100, Luca Weiss wrote: ... > >> Since the driver is now also registering as an IIO device[0], allow the > >> probe to continue without the thermal zone. > > > > Isn't it dangerous? > Why? Just asking to see if haven't missed anything potentially dangerous for HW at run-time. > The idea is that generic-adc-thermal is the middleman to convert > from one IIO input to one IIO output, and is purely informational, so > that user space can get some temperature value to display somewhere. > > How thermal management will be hooked up in the future to charger > drivers is a bit out of scope here I'd say. There's not even any cooling > support in the power supply core anymore, that was ripped out a while > ago if I'm not mistaken. Okay, so there is no possibility to get some thermal issues on running legacy HW (that relies on thermal to be present). If it's the case, no worries then. -- With Best Regards, Andy Shevchenko
© 2016 - 2026 Red Hat, Inc.