[PATCH 5/5] thermal/core: Avoid unbind for thermal zones without .unbind()

From: Zhang Rui
Date: Fri Mar 24 2023 - 03:08:41 EST


The ops->bind()/unbind() callback is the only way to bind/unbind a
cooling device to/from a thermal zone.

Optimize the code to avoid trying unbind when .unbind() callback doesn't
exist.

Signed-off-by: Zhang Rui <rui.zhang@xxxxxxxxx>
---
drivers/thermal/thermal_core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 9c447f22cb39..1af36450f13e 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1411,6 +1411,9 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
}
list_del(&tz->node);

+ if (!tz->ops->unbind)
+ goto unbind_done;
+
/* Unbind all cdevs associated with 'this' thermal zone */
list_for_each_entry(cdev, &thermal_cdev_list, node) {
struct thermal_instance *ti;
@@ -1428,8 +1431,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
continue;

unbind:
- if (tz->ops->unbind)
- tz->ops->unbind(tz, cdev);
+ tz->ops->unbind(tz, cdev);

/*
* The thermal instances for current thermal zone has been
@@ -1441,6 +1443,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
mutex_unlock(&cdev->lock);
}

+unbind_done:
mutex_unlock(&thermal_list_lock);

cancel_delayed_work_sync(&tz->poll_queue);
--
2.25.1