ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch()
Subsystems (3)
PATCH 1/1 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]
--- arch/arm/mach-omap2/powerdomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-omap2/powerdomain.c +1 -1
@@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)break ;case PWRDM_STATE_PREV : prev =pwrdm_read_prev_pwrst (pwrdm); -if (pwrdm->state != prev) +if (prev >=0 && pwrdm->state != prev) pwrdm->state_counter[prev]++;if (prev ==PWRDM_POWER_RET )_update_logic_membank_counters (pwrdm);
Signature · 1 line
2.34.1
Quoted 12 lines · Gustavo A. R. Silva
If function
pwrdm_read_prev_pwrst()returns-EINVAL, we will end up accessing arraypwrdm->state_counterthrough 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]
Quoted 6 lines
Fixes ba20bb126940 ("OMAP: PM counter infrastructure.")Reported-by kernel test robot <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>
Nice to see this work paying off.
Does the error case need further handling here?
Quoted 25 lines
--- arch/arm/mach-omap2/powerdomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/mach-omap2/powerdomain.c +1
-2@@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)break ;case PWRDM_STATE_PREV : prev =pwrdm_read_prev_pwrst (pwrdm); -if (pwrdm->state != prev) +if (prev >=0 && pwrdm->state != prev) pwrdm->state_counter[prev]++;if (prev ==PWRDM_POWER_RET )_update_logic_membank_counters (pwrdm); --2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Tony Lindgren
maintainerQuoted 10 lines · Gustavo A. R. Silva
If function
pwrdm_read_prev_pwrst()returns-EINVAL, we will end up accessing arraypwrdm->state_counterthrough 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]
Thanks applying into omap-for-v6.5/cleanup, seems this can wait for the merge window.
Regards,
Tony
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel