[PATCH v3 2/6] thermal: core: Free thermal zone ID later during removal

Rafael J. Wysocki posted 1 patch 2 months, 1 week ago
drivers/thermal/thermal_core.c |    5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH v3 2/6] thermal: core: Free thermal zone ID later during removal
Posted by Rafael J. Wysocki 2 months, 1 week ago
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The thermal zone removal ordering is different from the thermal zone
registration rollback path ordering and the former is arguably
problematic because freeing a thermal zone ID prematurely may cause
it to be used during the registration of another thermal zone which
may fail as a result.

Prevent that from occurring by changing the thermal zone removal
ordering to reflect the thermal zone registration rollback path
ordering.

Fixes: b31ef8285b19 ("thermal core: convert ID allocation to IDA")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v2 -> v3: New patch

---
 drivers/thermal/thermal_core.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1735,8 +1735,6 @@ void thermal_zone_device_unregister(stru
 
 	thermal_thresholds_exit(tz);
 	thermal_remove_hwmon_sysfs(tz);
-	ida_free(&thermal_tz_ida, tz->id);
-	ida_destroy(&tz->ida);
 
 	device_del(&tz->device);
 	put_device(&tz->device);
@@ -1747,6 +1745,9 @@ void thermal_zone_device_unregister(stru
 
 	thermal_set_governor(tz, NULL);
 
+	ida_free(&thermal_tz_ida, tz->id);
+	ida_destroy(&tz->ida);
+
 	kfree(tz->tzp);
 	kfree(tz);
 }