/* Check if there is any choice in the first place. */
        if (drv->state_count < 2) {
                idx = 0;
-               goto end;
+               goto out_tick;
        }
+
        if (!dev->states_usage[0].disable) {
                idx = 0;
                if (drv->states[1].target_residency_ns > duration_ns)
-                       goto end;
+                       goto out_tick;
        }
 
        cpu_data->utilized = teo_cpu_is_utilized(dev->cpu, cpu_data);
                 * anyway.
                 */
                if ((!idx && !(drv->states[0].flags & CPUIDLE_FLAG_POLLING) &&
-                   teo_time_ok(duration_ns)) || dev->states_usage[1].disable)
+                   teo_time_ok(duration_ns)) || dev->states_usage[1].disable) {
                        idx = 0;
-               else /* Assume that state 1 is not a polling one and use it. */
-                       idx = 1;
-
+                       goto out_tick;
+               }
+               /* Assume that state 1 is not a polling one and use it. */
+               idx = 1;
                goto end;
        }
 
        /* Avoid unnecessary overhead. */
        if (idx < 0) {
                idx = 0; /* No states enabled, must use 0. */
-               goto end;
-       } else if (idx == idx0) {
+               goto out_tick;
+       }
+
+       if (idx == idx0) {
+               /*
+                * This is the first enabled idle state, so use it, but do not
+                * allow the tick to be stopped it is shallow enough.
+                */
+               duration_ns = drv->states[idx].target_residency_ns;
                goto end;
        }
 
 
 end:
        /*
-        * Don't stop the tick if the selected state is a polling one or if the
-        * expected idle duration is shorter than the tick period length.
+        * Allow the tick to be stopped unless the selected state is a polling
+        * one or the expected idle duration is shorter than the tick period
+        * length.
         */
-       if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) ||
-           duration_ns < TICK_NSEC) && !tick_nohz_tick_stopped()) {
-               *stop_tick = false;
+       if ((!(drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
+           duration_ns >= TICK_NSEC) || tick_nohz_tick_stopped())
+               return idx;
 
-               /*
-                * The tick is not going to be stopped, so if the target
-                * residency of the state to be returned is not within the time
-                * till the closest timer including the tick, try to correct
-                * that.
-                */
-               if (idx > idx0 &&
-                   drv->states[idx].target_residency_ns > delta_tick)
-                       idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false);
-       }
+       /*
+        * The tick is not going to be stopped, so if the target residency of
+        * the state to be returned is not within the time till the closest
+        * timer including the tick, try to correct that.
+        */
+       if (idx > idx0 &&
+           drv->states[idx].target_residency_ns > delta_tick)
+               idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false);
 
+out_tick:
+       *stop_tick = false;
        return idx;
 }