• Rafael J. Wysocki's avatar
    thermal: core: Rework thermal zone availability check · b38aa87f
    Rafael J. Wysocki authored
    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: 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>
    b38aa87f
thermal_core.c 41.4 KB