thermal: core: More cleanups after bind/unbind changes
cover thermal: core: More cleanups after bind/unbind changes
Hi Everyone,
These are additional cleanups that can be done on top of
https://lore.kernel.org/linux-pm/[email protected]/
and
https://lore.kernel.org/linux-pm/[email protected]/
Thanks!
PATCH 1/4 thermal: core: Drop redundant lockdep_assert_held()
From: Rafael J. Wysocki <[email protected]>
Along the lines of commit 24aad192c671 ("thermal: core: Drop redundant checks from thermal_bind_cdev_to_trip()") notice that thermal_unbind_cdev_from_trip() is only called by thermal_zone_cdev_unbind() under the thermal zone lock, so it need not use lockdep_assert_held() for that lock.
No functional impact.
--- drivers/thermal/thermal_core.c | 2 -- 1 file changed, 2 deletions(-)
drivers/thermal/thermal_core.c +0 -2
@@ -891,8 +891,6 @@ static void thermal_unbind_cdev_from_tri {struct thermal_instance *pos, *next; -lockdep_assert_held (&tz->lock); -mutex_lock (&cdev->lock);list_for_each_entry_safe (pos, next, &tz->thermal_instances, tz_node) {if (pos->trip == trip && pos->cdev == cdev) {
PATCH 2/4 thermal: core: Drop dead code from monitor_thermal_zone()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since monitor_thermal_zone() is only called when the given thermal zone has been enabled, as per the thermal_zone_device_is_enabled() check in __thermal_zone_device_update(), the tz->mode check in it always evaluates to "false" and the thermal_zone_device_set_polling() invocation depending on it is dead code, so drop it.
No functional impact.
--- drivers/thermal/thermal_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/thermal/thermal_core.c +1 -3
@@ -364,9 +364,7 @@ static void thermal_zone_recheck(structstatic void monitor_thermal_zone (struct thermal_zone_device *tz) { -if (tz->mode !=THERMAL_DEVICE_ENABLED ) -thermal_zone_device_set_polling (tz,0 ); -else if (tz->passive >0 ) +if (tz->passive >0 )thermal_zone_device_set_polling (tz, tz->passive_delay_jiffies);else if (tz->polling_delay_jiffies)thermal_zone_device_set_polling (tz, tz->polling_delay_jiffies);
PATCH 3/4 thermal: core: Check passive delay in monitor_thermal_zone()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The only case in which thermal_zone_device_set_polling() is called with its second argument equal to zero is when passive cooling is under way and passive_delay_jiffies is 0, which only happens when the given thermal zone is not polled at all.
If monitor_thermal_zone() is modified to check passive_delay_jiffies directly, the check of the thermal_zone_device_set_polling() second argument against 0 can be dropped and a passive_delay check can be dropped from thermal_zone_device_register_with_trips(), so change the code accordingly.
No intentional functional impact.
--- drivers/thermal/thermal_core.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/thermal/thermal_core.c +3 -13
@@ -323,11 +323,6 @@ static void thermal_zone_broken_disable(static void thermal_zone_device_set_polling (struct thermal_zone_device *tz,unsigned long delay) { -if (!delay) { -cancel_delayed_work (&tz->poll_queue); -return ; - } -if (delay >HZ ) delay =round_jiffies_relative (delay);
@@ -364,7 +359,7 @@ static void thermal_zone_recheck(structstatic void monitor_thermal_zone (struct thermal_zone_device *tz) { -if (tz->passive >0 ) +if (tz->passive >0 && tz->passive_delay_jiffies)thermal_zone_device_set_polling (tz, tz->passive_delay_jiffies);else if (tz->polling_delay_jiffies)thermal_zone_device_set_polling (tz, tz->polling_delay_jiffies);
@@ -1411,13 +1406,8 @@ thermal_zone_device_register_with_trips(if (num_trips >0 && !trips)return ERR_PTR (-EINVAL ); -if (polling_delay) { -if (passive_delay > polling_delay) -return ERR_PTR (-EINVAL ); - -if (!passive_delay) - passive_delay = polling_delay; - } +if (polling_delay && passive_delay > polling_delay) +return ERR_PTR (-EINVAL );if (!thermal_class)return ERR_PTR (-ENODEV );
PATCH 4/4 thermal: core: Drop thermal_zone_device_is_enabled()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There are only two callers of thermal_zone_device_is_enabled() and one of them call is under the zone lock and the other one uses lockdep_assert_held() on that lock. Thus the lockdep_assert_held() in thermal_zone_device_is_enabled() is redundant and it could be dropped, but then the function would merely become a wrapper around a simple tz->mode check that is more convenient to do directly.
Accordingly, drop thermal_zone_device_is_enabled() altogether and update its callers to check tz->mode directly as appropriate.
While at it, combine the tz->mode and tz->suspended checks in __thermal_zone_device_update() because they are of a similar category and if any of them evaluates to "true", the outcome is the same.
No intentinal functional impact.
--- drivers/thermal/thermal_core.c | 12 +----------- drivers/thermal/thermal_core.h | 3 --- drivers/thermal/thermal_sysfs.c | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-)
drivers/thermal/thermal_core.c +1 -11
@@ -547,10 +547,7 @@ void __thermal_zone_device_update(structint low = -INT_MAX , high =INT_MAX ;int temp, ret; -if (tz->suspended) -return ; - -if (!thermal_zone_device_is_enabled (tz)) +if (tz->suspended || tz->mode !=THERMAL_DEVICE_ENABLED )return ; ret =__thermal_zone_get_temp (tz, &temp);
@@ -652,13 +649,6 @@ int thermal_zone_device_disable(struct t }EXPORT_SYMBOL_GPL (thermal_zone_device_disable); -int thermal_zone_device_is_enabled (struct thermal_zone_device *tz) -{ -lockdep_assert_held (&tz->lock); - -return tz->mode ==THERMAL_DEVICE_ENABLED ; -} -static bool thermal_zone_is_present (struct thermal_zone_device *tz) {return !list_empty (&tz->node);
drivers/thermal/thermal_core.h +0 -3
@@ -284,7 +284,4 @@ thermal_cooling_device_stats_update(stru unsigned long new_state) {}#endif /* CONFIG_THERMAL_STATISTICS */ -/* device tree support */ -int thermal_zone_device_is_enabled (struct thermal_zone_device *tz); -#endif /* __THERMAL_CORE_H__ */
drivers/thermal/thermal_sysfs.c +1 -1
@@ -53,7 +53,7 @@ mode_show(struct device *dev, struct devint enabled;mutex_lock (&tz->lock); - enabled =thermal_zone_device_is_enabled (tz); + enabled = tz->mode ==THERMAL_DEVICE_ENABLED ;mutex_unlock (&tz->lock);return sprintf (buf,"%s\n" , enabled ?"enabled" :"disabled" );