cpuidle: teo: Fix alternative idle state lookup
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 30 Jul 2021 14:38:07 +0000 (16:38 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 3 Aug 2021 13:18:57 +0000 (15:18 +0200)
commitc2ec772b87408259cb01209a22fb4e1ae7d346de
tree80914c2d3629737d8197d0cc38e0ec92b44b86f6
parentc500bee1c5b2f1d59b1081ac879d73268ab0ff17
cpuidle: teo: Fix alternative idle state lookup

There are three mistakes in the loop in teo_select() that is looking
for an alternative candidate idle state.  First, it should walk all
of the idle states shallower than the current candidate one,
including all of the disabled ones, but it terminates after the first
enabled idle state.  Second, it should not terminate its last step
if idle state 0 is disabled (which is related to the first issue).
Finally, it may return the current alternative candidate idle state
prematurely if the time span criterion is not met by the idle state
under consideration at the moment.

To address the issues mentioned above, make the loop in question walk
all of the idle states shallower than the current candidate idle state
all the way down to idle state 0 and rearrange the checks in it.

Fixes: 77577558f25d ("cpuidle: teo: Rework most recent idle duration values treatment")
Reported-by: Doug Smythies <dsmythies@telus.net>
Tested-by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpuidle/governors/teo.c