[PATCH 04/16] intel_idle: Fix deallocation order on the driver exit path.

Tim Gardner tim.gardner at canonical.com
Wed Aug 24 21:29:34 UTC 2016

From: Richard Cochran <rcochran at linutronix.de>

BugLink: http://bugs.launchpad.net/bugs/1591821

In the module_exit() method, this driver first frees its per-CPU
pointer, then unregisters a callback making use of the pointer.
Furthermore, the function, intel_idle_cpuidle_devices_uninit, is racy
against CPU hot plugging as it calls for_each_online_cpu().

This patch corrects the issues by unregistering first on the exit path
while holding the hot plug lock.

Signed-off-by: Richard Cochran <rcochran at linutronix.de>
Signed-off-by: Len Brown <len.brown at intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
(cherry picked from commit 51319918bcc31f901646fc66348d41cf74ee0566)
Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
 drivers/idle/intel_idle.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index cb85c4c..4a1de3d 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -1242,16 +1242,16 @@ static int __init intel_idle_init(void)
 static void __exit intel_idle_exit(void)
-	intel_idle_cpuidle_devices_uninit();
-	cpuidle_unregister_driver(&intel_idle_driver);
 	if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
 		on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
+	intel_idle_cpuidle_devices_uninit();
+	cpuidle_unregister_driver(&intel_idle_driver);

More information about the kernel-team mailing list