Skip to content

Commit 847fb80

Browse files
GustavoARSilvatmlind
authored andcommitted
ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch()
If function pwrdm_read_prev_pwrst() returns -EINVAL, we will end up accessing array pwrdm->state_counter through negative index -22. This is wrong and the compiler is legitimately warning us about this potential problem. Fix this by sanity checking the value stored in variable _prev_ before accessing array pwrdm->state_counter. Address the following -Warray-bounds warning: arch/arm/mach-omap2/powerdomain.c:178:45: warning: array subscript -22 is below array bounds of 'unsigned int[4]' [-Warray-bounds] Link: KSPP#307 Fixes: ba20bb1 ("OMAP: PM counter infrastructure.") Cc: [email protected] Reported-by: kernel test robot <[email protected]> Link: https://lore.kernel.org/lkml/20230607050639.LzbPn%[email protected]/ Signed-off-by: Gustavo A. R. Silva <[email protected]> Message-ID: <ZIFVGwImU3kpaGeH@work> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Tony Lindgren <[email protected]>
1 parent c63f5b4 commit 847fb80

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/arm/mach-omap2/powerdomain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
174174
break;
175175
case PWRDM_STATE_PREV:
176176
prev = pwrdm_read_prev_pwrst(pwrdm);
177-
if (pwrdm->state != prev)
177+
if (prev >= 0 && pwrdm->state != prev)
178178
pwrdm->state_counter[prev]++;
179179
if (prev == PWRDM_POWER_RET)
180180
_update_logic_membank_counters(pwrdm);

0 commit comments

Comments
 (0)