Skip to content

Commit daae9c1

Browse files
committed
thermal: core: Free thermal zone ID later during removal
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. Also more the ida_destroy() call from thermal_zone_device_unregister() to thermal_release() for consistency. Fixes: b31ef82 ("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> Link: https://patch.msgid.link/5063934.GXAFRqVoOG@rafael.j.wysocki
1 parent 41ff66b commit daae9c1

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/thermal/thermal_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ static void thermal_release(struct device *dev)
965965
tz = to_thermal_zone(dev);
966966
thermal_zone_destroy_device_groups(tz);
967967
thermal_set_governor(tz, NULL);
968+
ida_destroy(&tz->ida);
968969
mutex_destroy(&tz->lock);
969970
complete(&tz->removal);
970971
} else if (!strncmp(dev_name(dev), "cooling_device",
@@ -1729,15 +1730,16 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
17291730

17301731
thermal_thresholds_exit(tz);
17311732
thermal_remove_hwmon_sysfs(tz);
1732-
ida_free(&thermal_tz_ida, tz->id);
1733-
ida_destroy(&tz->ida);
17341733

17351734
device_del(&tz->device);
17361735
put_device(&tz->device);
17371736

17381737
thermal_notify_tz_delete(tz);
17391738

17401739
wait_for_completion(&tz->removal);
1740+
1741+
ida_free(&thermal_tz_ida, tz->id);
1742+
17411743
kfree(tz->tzp);
17421744
kfree(tz);
17431745
}

0 commit comments

Comments
 (0)