===================================================================
@@ -44,6 +44,18 @@ void disable_cpuidle(void)
off = 1;
}
+int cpuidle_check_availability(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev)
+{
+ if (off || !initialized)
+ return -ENODEV;
+
+ if (!drv || !dev || !dev->enabled)
+ return -EBUSY;
+
+ return 0;
+}
+
/**
* cpuidle_play_dead - cpu off-lining
*
@@ -76,8 +88,13 @@ static int cpuidle_find_deepest_state(st
struct cpuidle_device *dev, bool freeze)
{
unsigned int latency_req = 0;
- int i, ret = freeze ? -1 : CPUIDLE_DRIVER_STATE_START - 1;
+ int i, ret;
+
+ ret = cpuidle_check_availability(drv, dev);
+ if (ret)
+ return ret;
+ ret = freeze ? -1 : CPUIDLE_DRIVER_STATE_START - 1;
for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
struct cpuidle_state *s = &drv->states[i];
struct cpuidle_state_usage *su = &dev->states_usage[i];
@@ -205,13 +222,8 @@ int cpuidle_enter_state(struct cpuidle_d
*/
int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
{
- if (off || !initialized)
- return -ENODEV;
-
- if (!drv || !dev || !dev->enabled)
- return -EBUSY;
-
- return cpuidle_curr_governor->select(drv, dev);
+ int ret = cpuidle_check_availability(drv, dev);
+ return ret ? ret : cpuidle_curr_governor->select(drv, dev);
}
/**