struct device *device = get_cpu_device(dev->cpu);
        int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
        int i;
+       int first_idx;
+       int idx;
        unsigned int interactivity_req;
        unsigned int expected_interval;
        unsigned long nr_iowaiters, cpu_load;
                if (data->next_timer_us > polling_threshold &&
                    latency_req > s->exit_latency && !s->disabled &&
                    !dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable)
-                       data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
+                       first_idx = CPUIDLE_DRIVER_STATE_START;
                else
-                       data->last_state_idx = CPUIDLE_DRIVER_STATE_START - 1;
+                       first_idx = CPUIDLE_DRIVER_STATE_START - 1;
        } else {
-               data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
+               first_idx = 0;
        }
 
        /*
         * Find the idle state with the lowest power while satisfying
         * our constraints.
         */
-       for (i = data->last_state_idx + 1; i < drv->state_count; i++) {
+       idx = -1;
+       for (i = first_idx; i < drv->state_count; i++) {
                struct cpuidle_state *s = &drv->states[i];
                struct cpuidle_state_usage *su = &dev->states_usage[i];
 
                if (s->disabled || su->disable)
                        continue;
+               if (idx == -1)
+                       idx = i; /* first enabled state */
                if (s->target_residency > data->predicted_us)
                        break;
                if (s->exit_latency > latency_req)
                        break;
 
-               data->last_state_idx = i;
+               idx = i;
        }
 
+       if (idx == -1)
+               idx = 0; /* No states enabled. Must use 0. */
+
+       data->last_state_idx = idx;
+
        return data->last_state_idx;
 }