]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thermal: core: Allocate thermal_class statically
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 7 Apr 2026 14:07:51 +0000 (16:07 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 8 Apr 2026 10:30:31 +0000 (12:30 +0200)
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 <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/10831981.nUPlyArG6x@rafael.j.wysocki
drivers/thermal/thermal_core.c

index e3e8331ca24e6c5ab25412da73b0f4ae144b8f63..f0f3a628c00c9f89173f81497b6349692b983562 100644 (file)
@@ -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)