From: Rafael J. Wysocki Date: Tue, 7 Apr 2026 14:07:51 +0000 (+0200) Subject: thermal: core: Allocate thermal_class statically X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c4c6a8646359612db34c76f58799f5206945e365;p=thirdparty%2Fkernel%2Flinux.git thermal: core: Allocate thermal_class statically Define thermal_class as a static structure to simplify thermal_init() and to simplify thermal class availability checks that will need to be carried out during the suspend and resume of thermal zones after subsequent changes. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/10831981.nUPlyArG6x@rafael.j.wysocki --- diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e3e8331ca24e6..f0f3a628c00c9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -972,7 +972,11 @@ static void thermal_release(struct device *dev) } } -static struct class *thermal_class; +static const struct class thermal_class = { + .name = "thermal", + .dev_release = thermal_release, +}; +static bool thermal_class_unavailable __ro_after_init = true; static inline void print_bind_err_msg(struct thermal_zone_device *tz, @@ -1065,7 +1069,7 @@ __thermal_cooling_device_register(struct device_node *np, !ops->set_cur_state) return ERR_PTR(-EINVAL); - if (!thermal_class) + if (thermal_class_unavailable) return ERR_PTR(-ENODEV); cdev = kzalloc_obj(*cdev); @@ -1088,7 +1092,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->devdata = devdata; ret = cdev->ops->get_max_state(cdev, &cdev->max_state); @@ -1536,7 +1540,7 @@ thermal_zone_device_register_with_trips(const char *type, if (polling_delay && passive_delay > polling_delay) return ERR_PTR(-EINVAL); - if (!thermal_class) + if (thermal_class_unavailable) return ERR_PTR(-ENODEV); tz = kzalloc_flex(*tz, trips, num_trips); @@ -1572,7 +1576,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->devdata = devdata; tz->num_trips = num_trips; for_each_trip_desc(tz, td) { @@ -1914,21 +1918,11 @@ static int __init thermal_init(void) if (result) goto destroy_workqueue; - thermal_class = kzalloc_obj(*thermal_class); - if (!thermal_class) { - result = -ENOMEM; + result = class_register(&thermal_class); + if (result) goto unregister_governors; - } - thermal_class->name = "thermal"; - thermal_class->dev_release = thermal_release; - - result = class_register(thermal_class); - if (result) { - kfree(thermal_class); - thermal_class = NULL; - goto unregister_governors; - } + thermal_class_unavailable = false; result = register_pm_notifier(&thermal_pm_nb); if (result)