Re: [PATCH 3/4] thermal/core: Allocate the thermal class dynamically
From: Rafael J. Wysocki
Date: Fri May 08 2026 - 14:25:32 EST
On Fri, May 8, 2026 at 8:05 PM Daniel Lezcano
<daniel.lezcano@xxxxxxxxxxxxxxxx> wrote:
>
> Use class_create() instead of a statically allocated struct class.
>
> This allows the thermal class to be managed through a dynamically
> allocated class object and avoids keeping a static class instance
> around.
I changed it the other way around during the last cycle, so is it
really worth changing again?
> Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxxxxxxxx>
> ---
> drivers/thermal/thermal_core.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index a79fc4cdb078..748ab76823a3 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -949,9 +949,7 @@ static void thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
> kfree(pos);
> }
>
> -static const struct class thermal_class = {
> - .name = "thermal",
> -};
> +static struct class *thermal_class;
> static bool thermal_class_unavailable __ro_after_init = true;
>
> static inline
> @@ -1078,7 +1076,7 @@ __thermal_cooling_device_register(struct device_node *np,
> cdev->np = np;
> cdev->ops = ops;
> cdev->updated = false;
> - cdev->device.class = &thermal_class;
> + cdev->device.class = thermal_class;
> cdev->device.release = thermal_cdev_release;
> cdev->devdata = devdata;
>
> @@ -1574,7 +1572,7 @@ thermal_zone_device_register_with_trips(const char *type,
> if (!tz->ops.critical)
> tz->ops.critical = thermal_zone_device_critical;
>
> - tz->device.class = &thermal_class;
> + tz->device.class = thermal_class;
> tz->device.release = thermal_zone_device_release;
> tz->devdata = devdata;
> tz->num_trips = num_trips;
> @@ -1898,15 +1896,18 @@ static int __init thermal_init(void)
> if (result)
> goto destroy_workqueue;
>
> - result = class_register(&thermal_class);
> - if (result)
> + thermal_class = class_create("thermal");
> + if (IS_ERR(thermal_class)) {
> + result = PTR_ERR(thermal_class);
> goto unregister_governors;
> + }
>
> thermal_class_unavailable = false;
>
> return 0;
>
> unregister_governors:
> + thermal_class = NULL;
> thermal_unregister_governors();
> destroy_workqueue:
> destroy_workqueue(thermal_wq);
> --
> 2.43.0
>
>