[PATCH] cpuidle: fix fallback mechanism for suspend to idle in absence of enter_freeze

From: Sudeep Holla
Date: Thu Jan 21 2016 - 06:19:42 EST


Commit 51164251f5c3 ("sched / idle: Drop default_idle_call() fallback
from call_cpuidle()") made find_deepest_state() return non-negative
value and check all the states with index > 0. Also a result,
find_deepest_state() returns 0 even when enter_freeze callbacks are not
implemented and enter_freeze_proper is called which ends up crashing
the kernel.

This patch updates the check for index > 0 in cpuidle_enter_freeze and
cpuidle_idle_call(when idle_should_freeze is true) to restore the
suspend-to-idle functionality in absence of enter_freeze callback.

Fixes: 51164251f5c3 ("sched / idle: Drop default_idle_call() fallback from call_cpuidle()")
Cc: "Rafael J. Wysocki" <rjw@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Sudeep Holla <sudeep.holla@xxxxxxx>
---
drivers/cpuidle/cpuidle.c | 2 +-
kernel/sched/idle.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

Hi Rafael,

I assume you prefer to retain find_deepest_state return non-negative
values, so I took this approach for fixing the bug. Do you think we
need to support enter_freeze_proper for index 0 ?

Regards,
Sudeep

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 046423b0c5ca..f996efc56605 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -153,7 +153,7 @@ int cpuidle_enter_freeze(struct cpuidle_driver *drv, struct cpuidle_device *dev)
* be frozen safely.
*/
index = find_deepest_state(drv, dev, UINT_MAX, 0, true);
- if (index >= 0)
+ if (index > 0)
enter_freeze_proper(drv, dev, index);

return index;
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index de0e786b2667..544a7133cbd1 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -162,7 +162,7 @@ static void cpuidle_idle_call(void)
*/
if (idle_should_freeze()) {
entered_state = cpuidle_enter_freeze(drv, dev);
- if (entered_state >= 0) {
+ if (entered_state > 0) {
local_irq_enable();
goto exit_idle;
}
--
1.9.1