cpuidle: Do not access cpuidle_devices when !CONFIG_CPU_IDLE
authorCatalin Marinas <catalin.marinas@arm.com>
Wed, 1 Jun 2016 17:52:16 +0000 (18:52 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Dec 2016 04:52:01 +0000 (13:52 +0900)
The cpuidle_devices per-CPU variable is only defined when CPU_IDLE is
enabled. Commit c8cc7d4de7a4 ("sched/idle: Reorganize the idle loop")
removed the #ifdef CONFIG_CPU_IDLE around cpuidle_idle_call() with the
compiler optimising away __this_cpu_read(cpuidle_devices). However, with
CONFIG_UBSAN && !CONFIG_CPU_IDLE, this optimisation no longer happens
and the kernel fails to link since cpuidle_devices is not defined.

This patch introduces an accessor function for the current CPU cpuidle
device (returning NULL when !CONFIG_CPU_IDLE) and uses it in
cpuidle_idle_call().

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: 4.5+ <stable@vger.kernel.org> # 4.5+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
[Backport from mainline to fix build error for CONFIG_UBSAN && ! CONFIG_CPU_IDLE]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I447cd7f1076903bc036eb0e832d9cabba91099b7

include/linux/cpuidle.h
kernel/sched/idle.c

index 9c5e892..111ead2 100644 (file)
@@ -157,6 +157,8 @@ extern int cpuidle_enter_freeze(struct cpuidle_driver *drv,
                                struct cpuidle_device *dev);
 
 extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
+static inline struct cpuidle_device *cpuidle_get_device(void)
+{return __this_cpu_read(cpuidle_devices); }
 #else
 static inline void disable_cpuidle(void) { }
 static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
@@ -198,6 +200,7 @@ static inline int cpuidle_enter_freeze(struct cpuidle_driver *drv,
 {return -ENODEV; }
 static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
        struct cpuidle_device *dev) {return NULL; }
+static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
 #endif
 
 #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
index fefcb1f..437d577 100644 (file)
@@ -78,7 +78,7 @@ void __weak arch_cpu_idle(void)
  */
 static void cpuidle_idle_call(void)
 {
-       struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
+       struct cpuidle_device *dev = cpuidle_get_device();
        struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
        int next_state, entered_state;
        bool reflect;