s64 latency_req = cpuidle_governor_latency_req(dev->cpu);
        u64 duration_ns;
        unsigned int hits, misses, early_hits;
-       int max_early_idx, constraint_idx, idx, i;
+       int max_early_idx, prev_max_early_idx, constraint_idx, idx, i;
        ktime_t delta_tick;
 
        if (dev->last_state_idx >= 0) {
        misses = 0;
        early_hits = 0;
        max_early_idx = -1;
+       prev_max_early_idx = -1;
        constraint_idx = drv->state_count;
        idx = -1;
 
                         */
                        if (!(tick_nohz_tick_stopped() &&
                              drv->states[idx].target_residency_ns < TICK_NSEC)) {
+                               prev_max_early_idx = max_early_idx;
                                early_hits = cpu_data->states[i].early_hits;
                                max_early_idx = idx;
                        }
                if (early_hits < cpu_data->states[i].early_hits &&
                    !(tick_nohz_tick_stopped() &&
                      drv->states[i].target_residency_ns < TICK_NSEC)) {
+                       prev_max_early_idx = max_early_idx;
                        early_hits = cpu_data->states[i].early_hits;
                        max_early_idx = i;
                }
         * "early hits" metric, but if that cannot be determined, just use the
         * state selected so far.
         */
-       if (hits <= misses && max_early_idx >= 0) {
-               idx = max_early_idx;
-               duration_ns = drv->states[idx].target_residency_ns;
+       if (hits <= misses) {
+               /*
+                * The current candidate state is not suitable, so take the one
+                * whose "early hits" metric is the maximum for the range of
+                * shallower states.
+                */
+               if (idx == max_early_idx)
+                       max_early_idx = prev_max_early_idx;
+
+               if (max_early_idx >= 0) {
+                       idx = max_early_idx;
+                       duration_ns = drv->states[idx].target_residency_ns;
+               }
        }
 
        /*