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

Message ID 20230324070807.6342-5-rui.zhang@intel.com
State New
Headers
Series [v2,1/5] thermal/core: Update cooling device during thermal zone unregistration |

Commit Message

Zhang, Rui March 24, 2023, 7:08 a.m. UTC
  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@intel.com>
---
 drivers/thermal/thermal_core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

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);