Re: [PATCH 3/9] thermal/core: Ensure that thermal device is registered in thermal_zone_get_temp

From: Guenter Roeck
Date: Thu Nov 10 2022 - 09:13:57 EST


On Wed, Nov 09, 2022 at 08:07:48PM +0100, Rafael J. Wysocki wrote:
[ ... ]
> >
> > diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
> > index c65cdce8f856..3bac0b7a4c62 100644
> > --- a/drivers/thermal/thermal_helpers.c
> > +++ b/drivers/thermal/thermal_helpers.c
> > @@ -115,7 +115,12 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
> > int ret;
> >
> > mutex_lock(&tz->lock);
> > + if (!device_is_registered(&tz->device)) {
> > + ret = -ENODEV;
> > + goto unlock;
> > + }
> > ret = __thermal_zone_get_temp(tz, temp);
> > +unlock:
>
> I would do it this way:
>
> if (device_is_registered(&tz->device))
> ret = __thermal_zone_get_temp(tz, temp);
> else
> ret = -ENODEV;
>
Done in all patches. Agreed, that looks much better.

Thanks,
Guenter