Skip to content

Commit eb295d2

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 1873eb8 commit eb295d2

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",
@@ -1726,15 +1727,16 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
17261727

17271728
thermal_thresholds_exit(tz);
17281729
thermal_remove_hwmon_sysfs(tz);
1729-
ida_free(&thermal_tz_ida, tz->id);
1730-
ida_destroy(&tz->ida);
17311730

17321731
device_del(&tz->device);
17331732
put_device(&tz->device);
17341733

17351734
thermal_notify_tz_delete(tz);
17361735

17371736
wait_for_completion(&tz->removal);
1737+
1738+
ida_free(&thermal_tz_ida, tz->id);
1739+
17381740
kfree(tz->tzp);
17391741
kfree(tz);
17401742
}

0 commit comments

Comments
 (0)