thermal: core: Introduce thermal_cooling_device_update()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 17 Mar 2023 17:01:26 +0000 (18:01 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 22 Mar 2023 14:20:38 +0000 (15:20 +0100)
commit790930f44289c8209c57461b2db499fcc702e0b3
treec40566996b039965cbe1e29fb84d4fa32e9987c1
parentc43198af05cffa5de8d4f356c40ce4bdca066272
thermal: core: Introduce thermal_cooling_device_update()

Introduce a core thermal API function, thermal_cooling_device_update(),
for updating the max_state value for a cooling device and rearranging
its statistics in sysfs after a possible change of its ->get_max_state()
callback return value.

That callback is now invoked only once, during cooling device
registration, to populate the max_state field in the cooling device
object, so if its return value changes, it needs to be invoked again
and the new return value needs to be stored as max_state.  Moreover,
the statistics presented in sysfs need to be rearranged in general,
because there may not be enough room in them to store data for all
of the possible states (in the case when max_state grows).

The new function takes care of that (and some other minor things
related to it), but some extra locking and lockdep annotations are
added in several places too to protect against crashes in the cases
when the statistics are not present or when a stale max_state value
might be used by sysfs attributes.

Note that the actual user of the new function will be added separately.

Link: https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h
drivers/thermal/thermal_sysfs.c
include/linux/thermal.h