Commit 4649620d authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

thermal: core: Make thermal_zone_device_unregister() return after freeing the zone

Make thermal_zone_device_unregister() wait until all of the references
to the given thermal zone object have been dropped and free it before
returning.

This guarantees that when thermal_zone_device_unregister() returns,
there is no leftover activity regarding the thermal zone in question
which is required by some of its callers (for instance, modular driver
code that wants to know when it is safe to let the module go away).

Subsequently, this will allow some confusing device_is_registered()
checks to be dropped from the thermal sysfs and core code.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-and-tested-by: default avatarLukasz Luba <lukasz.luba@arm.com>
Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent 18dfb0e4
...@@ -822,7 +822,7 @@ static void thermal_release(struct device *dev) ...@@ -822,7 +822,7 @@ static void thermal_release(struct device *dev)
tz = to_thermal_zone(dev); tz = to_thermal_zone(dev);
thermal_zone_destroy_device_groups(tz); thermal_zone_destroy_device_groups(tz);
mutex_destroy(&tz->lock); mutex_destroy(&tz->lock);
kfree(tz); complete(&tz->removal);
} else if (!strncmp(dev_name(dev), "cooling_device", } else if (!strncmp(dev_name(dev), "cooling_device",
sizeof("cooling_device") - 1)) { sizeof("cooling_device") - 1)) {
cdev = to_cooling_device(dev); cdev = to_cooling_device(dev);
...@@ -1315,6 +1315,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t ...@@ -1315,6 +1315,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
INIT_LIST_HEAD(&tz->thermal_instances); INIT_LIST_HEAD(&tz->thermal_instances);
ida_init(&tz->ida); ida_init(&tz->ida);
mutex_init(&tz->lock); mutex_init(&tz->lock);
init_completion(&tz->removal);
id = ida_alloc(&thermal_tz_ida, GFP_KERNEL); id = ida_alloc(&thermal_tz_ida, GFP_KERNEL);
if (id < 0) { if (id < 0) {
result = id; result = id;
...@@ -1494,6 +1495,9 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) ...@@ -1494,6 +1495,9 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
put_device(&tz->device); put_device(&tz->device);
thermal_notify_tz_delete(tz_id); thermal_notify_tz_delete(tz_id);
wait_for_completion(&tz->removal);
kfree(tz);
} }
EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
......
...@@ -117,6 +117,7 @@ struct thermal_cooling_device { ...@@ -117,6 +117,7 @@ struct thermal_cooling_device {
* @id: unique id number for each thermal zone * @id: unique id number for each thermal zone
* @type: the thermal zone device type * @type: the thermal zone device type
* @device: &struct device for this thermal zone * @device: &struct device for this thermal zone
* @removal: removal completion
* @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
* @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_type_attrs: attributes for trip points for sysfs: trip type
* @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
...@@ -156,6 +157,7 @@ struct thermal_zone_device { ...@@ -156,6 +157,7 @@ struct thermal_zone_device {
int id; int id;
char type[THERMAL_NAME_LENGTH]; char type[THERMAL_NAME_LENGTH];
struct device device; struct device device;
struct completion removal;
struct attribute_group trips_attribute_group; struct attribute_group trips_attribute_group;
struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_temp_attrs;
struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_type_attrs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment