Re: [PATCH v2] cpuidle: teo: Do not return a disabled idle state

From: Christian Loehle

Date: Fri Aug 28 2026 - 11:51:36 EST


On 8/28/26 04:24, Xueqin Luo wrote:
> If idle state 0 is disabled and none of the enabled idle states satisfies
> the PM QoS latency constraint, constraint_idx in teo_select() stays at its
> initial value of 0, because the loop that updates it starts at state 1,
> and so the candidate state index is capped at state 0, which is disabled,
> and that state is returned to the caller.
>
> The cpuidle core does not validate the returned state index against the
> per-state disable flags, so the CPU ends up entering the disabled state 0.
>
> To address this, ensure that constraint_idx is at least equal to the index
> of the first enabled idle state (idx0), so that the candidate state is
> never capped to a disabled one.
>
> Fixes: c410a9a142f1 ("cpuidle: teo: Change the main idle state selection logic")
> Signed-off-by: Xueqin Luo <luoxueqin@xxxxxxxxxx>

Reviewed-by: Christian Loehle <christian.loehle@xxxxxxx>

> ---
> v1 -> v2:
> - Instead of falling back to idx0 after the candidate index has been
> capped to a disabled state, ensure that constraint_idx is at least
> equal to idx0 before the capping check (suggested by Rafael J. Wysocki).
>
> drivers/cpuidle/governors/teo.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
> index ac43b9b013b3..906f4f89e365 100644
> --- a/drivers/cpuidle/governors/teo.c
> +++ b/drivers/cpuidle/governors/teo.c
> @@ -426,6 +426,17 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> }
> }
>
> + /*
> + * If the latency constraint does not allow any of the enabled idle
> + * states to be used, the candidate state index will be capped to 0
> + * by the check below, but state 0 may be disabled. To prevent the
> + * selection of a disabled state in that case, ensure that
> + * constraint_idx is at least equal to the index of the first
> + * enabled idle state.
> + */
> + if (constraint_idx < idx0)
> + constraint_idx = idx0;
> +
> /*
> * If there is a latency constraint, it may be necessary to select an
> * idle state shallower than the current candidate one.