cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too
Modify cpuidle_enter_freeze() to do the sanity checks done by
cpuidle_select() to avoid crashing the suspend-to-idle code
path in case something is missing.
Fixes: 3810631332
(PM / sleep: Re-implement suspend-to-idle handling)
Original-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
This commit is contained in:
parent
01e04f466e
commit
31a3409065
1 changed files with 16 additions and 7 deletions
|
@ -44,6 +44,12 @@ void disable_cpuidle(void)
|
||||||
off = 1;
|
off = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cpuidle_not_available(struct cpuidle_driver *drv,
|
||||||
|
struct cpuidle_device *dev)
|
||||||
|
{
|
||||||
|
return off || !initialized || !drv || !dev || !dev->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cpuidle_play_dead - cpu off-lining
|
* cpuidle_play_dead - cpu off-lining
|
||||||
*
|
*
|
||||||
|
@ -126,6 +132,9 @@ void cpuidle_enter_freeze(void)
|
||||||
struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
|
struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
if (cpuidle_not_available(drv, dev))
|
||||||
|
goto fallback;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the deepest state with ->enter_freeze present, which guarantees
|
* Find the deepest state with ->enter_freeze present, which guarantees
|
||||||
* that interrupts won't be enabled when it exits and allows the tick to
|
* that interrupts won't be enabled when it exits and allows the tick to
|
||||||
|
@ -143,9 +152,12 @@ void cpuidle_enter_freeze(void)
|
||||||
* at all and try to enter it normally.
|
* at all and try to enter it normally.
|
||||||
*/
|
*/
|
||||||
index = cpuidle_find_deepest_state(drv, dev, false);
|
index = cpuidle_find_deepest_state(drv, dev, false);
|
||||||
if (index >= 0)
|
if (index >= 0) {
|
||||||
cpuidle_enter(drv, dev, index);
|
cpuidle_enter(drv, dev, index);
|
||||||
else
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fallback:
|
||||||
arch_cpu_idle();
|
arch_cpu_idle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,12 +217,9 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
|
||||||
*/
|
*/
|
||||||
int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
|
int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
|
||||||
{
|
{
|
||||||
if (off || !initialized)
|
if (cpuidle_not_available(drv, dev))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
if (!drv || !dev || !dev->enabled)
|
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
return cpuidle_curr_governor->select(drv, dev);
|
return cpuidle_curr_governor->select(drv, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue