[PATCH v1] thermal: core: fix blocking in unregistering zone

From: Jiajia Liu

Date: Wed Apr 01 2026 - 22:20:09 EST


From: Jiajia Liu <liujiajia@xxxxxxxxxx>

When hwmon->tz_list has more than one member,
thermal_remove_hwmon_sysfs does not unregister hwmon->device.
Unregistering the zone which is parent of hwmon->device blocks
at wait_for_completion(&tz->removal). Add check and move hwmon
to other zone in thermal_remove_hwmon_sysfs.

One method of reproducing hung task is to unbind the first
acpitz zone on systems with two acpitz zones.

$ cd /sys/bus/platform/drivers/acpi-thermal/
$ ls
bind LNXTHERM:00 LNXTHERM:01 uevent unbind
$ echo 'LNXTHERM:00' | sudo tee unbind > /dev/null

Signed-off-by: Jiajia Liu <liujiajia@xxxxxxxxxx>
---
drivers/thermal/thermal_hwmon.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index b624892bc6d6..43cde079fef0 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -242,6 +242,15 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
list_del(&temp->hwmon_node);
kfree(temp);
if (!list_empty(&hwmon->tz_list)) {
+ if (hwmon->device->parent == &tz->device) {
+ struct thermal_hwmon_temp *first;
+
+ first = list_first_entry(&hwmon->tz_list,
+ struct thermal_hwmon_temp,
+ hwmon_node);
+ device_move(hwmon->device, &first->tz->device,
+ DPM_ORDER_DEV_AFTER_PARENT);
+ }
mutex_unlock(&thermal_hwmon_list_lock);
return;
}
--
2.53.0