Skip to content

Commit 50bb9fd

Browse files
rafaeljwgregkh
authored andcommitted
thermal: core: Free thermal zone ID later during removal
commit daae9c1 upstream. 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5a43859 commit 50bb9fd

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",
@@ -1730,15 +1731,16 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
17301731

17311732
thermal_thresholds_exit(tz);
17321733
thermal_remove_hwmon_sysfs(tz);
1733-
ida_free(&thermal_tz_ida, tz->id);
1734-
ida_destroy(&tz->ida);
17351734

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

17391738
thermal_notify_tz_delete(tz);
17401739

17411740
wait_for_completion(&tz->removal);
1741+
1742+
ida_free(&thermal_tz_ida, tz->id);
1743+
17421744
kfree(tz->tzp);
17431745
kfree(tz);
17441746
}

0 commit comments

Comments
 (0)