thermal: core: Rework thermal zone availability check
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 8 Dec 2023 19:20:00 +0000 (20:20 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 Dec 2023 12:01:03 +0000 (13:01 +0100)
commitb38aa87f67931e23ebc32c0ca00a86dfa4688719
tree70147e77b7e942e6fd1b9598d1f3e9140d0f0341
parentc3ffdfff978a089f2d678571664eecd41953253d
thermal: core: Rework thermal zone availability check

In order to avoid running __thermal_zone_device_update() for thermal
zones going away, the thermal zone lock is held around device_del()
in thermal_zone_device_unregister() and thermal_zone_device_update()
passes the given thermal zone device to device_is_registered().
This allows thermal_zone_device_update() to skip the
__thermal_zone_device_update() if device_del() has already run for
the thermal zone at hand.

However, instead of looking at driver core internals, the thermal
subsystem may as well rely on its own data structures for this
purpose.  Namely, if the thermal zone is not present in
thermal_tz_list, it can be regarded as unavailable, which in fact is
already the case in thermal_zone_device_unregister().  Accordingly,
the device_is_registered() check in thermal_zone_device_update() can
be replaced with checking whether or not the node list_head in struct
thermal_zone_device is empty, in which case it is not there in
thermal_tz_list.

To make this work, though, it is necessary to initialize tz->node
in thermal_zone_device_register_with_trips() before registering the
thermal zone device and it needs to be added to thermal_tz_list and
deleted from it under its zone lock.

After the above modifications, the zone lock does not need to be
held around device_del() in thermal_zone_device_unregister() any more.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-and-tested-by: Lukasz Luba <lukasz.luba@arm.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/thermal/thermal_core.c