public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal/core: update cooling device during thermal zone unregistration
@ 2023-03-21 15:46 Zhang Rui
  2023-03-21 19:43 ` Rafael J. Wysocki
  2023-03-22  8:07 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Zhang Rui @ 2023-03-21 15:46 UTC (permalink / raw)
  To: linux-pm, rafael.j.wysocki, daniel.lezcano; +Cc: linux-kernel

When unregistering a thermal zone device, update the cooling device in
case the cooling device is activated by the current thermal zone.

This fixes a problem that the frequency of ACPI processors are still
limited after unloading ACPI thermal driver while ACPI passive cooling
is activated.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index cfd4c1afeae7..9f120e3c9bf0 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1477,6 +1477,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	const struct thermal_zone_params *tzp;
 	struct thermal_cooling_device *cdev;
 	struct thermal_zone_device *pos = NULL;
+	struct thermal_instance *ti;
 
 	if (!tz)
 		return;
@@ -1497,9 +1498,22 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 
 	/* Unbind all cdevs associated with 'this' thermal zone */
 	list_for_each_entry(cdev, &thermal_cdev_list, node) {
+		mutex_lock(&tz->lock);
+		list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
+			if (ti->cdev == cdev)
+				break;
+		}
+
+		/* The cooling device is not used by current thermal zone */
+		if (ti->cdev != cdev) {
+			mutex_unlock(&tz->lock);
+			continue;
+		}
+		mutex_unlock(&tz->lock);
+
 		if (tz->ops->unbind) {
 			tz->ops->unbind(tz, cdev);
-			continue;
+			goto deactivate_cdev;
 		}
 
 		if (!tzp || !tzp->tbp)
@@ -1511,6 +1525,16 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 				tzp->tbp[i].cdev = NULL;
 			}
 		}
+
+deactivate_cdev:
+		/*
+		 * The thermal instances for current thermal zone has been
+		 * removed. Update the cooling device in case it is activated
+		 * by current thermal zone device.
+		 */
+		mutex_lock(&cdev->lock);
+		__thermal_cdev_update(cdev);
+		mutex_unlock(&cdev->lock);
 	}
 
 	mutex_unlock(&thermal_list_lock);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-22  8:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-21 15:46 [PATCH] thermal/core: update cooling device during thermal zone unregistration Zhang Rui
2023-03-21 19:43 ` Rafael J. Wysocki
2023-03-22  6:00   ` Zhang, Rui
2023-03-22  8:07 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox