Skip to content

Commit

Permalink
thermal/core: Delete device under thermal device zone lock
Browse files Browse the repository at this point in the history
Thermal device attributes may still be opened after unregistering
the thermal zone and deleting the thermal device.

Currently there is no protection against accessing thermal device
operations after unregistering a thermal zone. To enable adding
such protection, protect the device delete operation with the
thermal zone device mutex. This requires splitting the call to
device_unregister() into its components, device_del() and put_device().
Only the first call can be executed under mutex protection, since
put_device() may result in releasing the thermal zone device memory.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Guenter Roeck authored and Rafael J. Wysocki committed Nov 14, 2022
1 parent d35f29e commit 30b2ae0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,12 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
thermal_remove_hwmon_sysfs(tz);
ida_free(&thermal_tz_ida, tz->id);
ida_destroy(&tz->ida);
device_unregister(&tz->device);

mutex_lock(&tz->lock);
device_del(&tz->device);
mutex_unlock(&tz->lock);

put_device(&tz->device);

thermal_notify_tz_delete(tz_id);
}
Expand Down

0 comments on commit 30b2ae0

Please sign in to comment.