Commit c4c6a864 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/10831981.nUPlyArG6x@rafael.j.wysocki
parent 26fd03ef
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -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)