• Rafael J. Wysocki's avatar
    thermal: core: Introduce thermal_cooling_device_update() · 790930f4
    Rafael J. Wysocki authored
    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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    Tested-by: default avatarZhang Rui <rui.zhang@intel.com>
    Reviewed-by: default avatarZhang Rui <rui.zhang@intel.com>
    790930f4
thermal_core.c 41.6 KB