Skip to content

Commit c4c6a86

Browse files
committed
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 <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/10831981.nUPlyArG6x@rafael.j.wysocki
1 parent 26fd03e commit c4c6a86

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

drivers/thermal/thermal_core.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,11 @@ static void thermal_release(struct device *dev)
972972
}
973973
}
974974

975-
static struct class *thermal_class;
975+
static const struct class thermal_class = {
976+
.name = "thermal",
977+
.dev_release = thermal_release,
978+
};
979+
static bool thermal_class_unavailable __ro_after_init = true;
976980

977981
static inline
978982
void print_bind_err_msg(struct thermal_zone_device *tz,
@@ -1065,7 +1069,7 @@ __thermal_cooling_device_register(struct device_node *np,
10651069
!ops->set_cur_state)
10661070
return ERR_PTR(-EINVAL);
10671071

1068-
if (!thermal_class)
1072+
if (thermal_class_unavailable)
10691073
return ERR_PTR(-ENODEV);
10701074

10711075
cdev = kzalloc_obj(*cdev);
@@ -1088,7 +1092,7 @@ __thermal_cooling_device_register(struct device_node *np,
10881092
cdev->np = np;
10891093
cdev->ops = ops;
10901094
cdev->updated = false;
1091-
cdev->device.class = thermal_class;
1095+
cdev->device.class = &thermal_class;
10921096
cdev->devdata = devdata;
10931097

10941098
ret = cdev->ops->get_max_state(cdev, &cdev->max_state);
@@ -1536,7 +1540,7 @@ thermal_zone_device_register_with_trips(const char *type,
15361540
if (polling_delay && passive_delay > polling_delay)
15371541
return ERR_PTR(-EINVAL);
15381542

1539-
if (!thermal_class)
1543+
if (thermal_class_unavailable)
15401544
return ERR_PTR(-ENODEV);
15411545

15421546
tz = kzalloc_flex(*tz, trips, num_trips);
@@ -1572,7 +1576,7 @@ thermal_zone_device_register_with_trips(const char *type,
15721576
if (!tz->ops.critical)
15731577
tz->ops.critical = thermal_zone_device_critical;
15741578

1575-
tz->device.class = thermal_class;
1579+
tz->device.class = &thermal_class;
15761580
tz->devdata = devdata;
15771581
tz->num_trips = num_trips;
15781582
for_each_trip_desc(tz, td) {
@@ -1914,21 +1918,11 @@ static int __init thermal_init(void)
19141918
if (result)
19151919
goto destroy_workqueue;
19161920

1917-
thermal_class = kzalloc_obj(*thermal_class);
1918-
if (!thermal_class) {
1919-
result = -ENOMEM;
1921+
result = class_register(&thermal_class);
1922+
if (result)
19201923
goto unregister_governors;
1921-
}
19221924

1923-
thermal_class->name = "thermal";
1924-
thermal_class->dev_release = thermal_release;
1925-
1926-
result = class_register(thermal_class);
1927-
if (result) {
1928-
kfree(thermal_class);
1929-
thermal_class = NULL;
1930-
goto unregister_governors;
1931-
}
1925+
thermal_class_unavailable = false;
19321926

19331927
result = register_pm_notifier(&thermal_pm_nb);
19341928
if (result)

0 commit comments

Comments
 (0)