]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ep93xx: clock: Fix off by one in ep93xx_div_recalc_rate()
authorDan Carpenter <alexander.sverdlin@gmail.com>
Wed, 11 Sep 2024 07:39:15 +0000 (10:39 +0300)
committerArnd Bergmann <arnd@arndb.de>
Wed, 11 Sep 2024 12:20:27 +0000 (12:20 +0000)
The psc->div[] array has psc->num_div elements.  These values come from
when we call clk_hw_register_div().  It's adc_divisors and
ARRAY_SIZE(adc_divisors)) and so on.  So this condition needs to be >=
instead of > to prevent an out of bounds read.

Fixes: 9645ccc7bd7a ("ep93xx: clock: convert in-place to COMMON_CLK")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Reviewed-by: Nikita Shubin <nikita.shubin@maquefel.me>
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Link: https://lore.kernel.org/r/1caf01ad4c0a8069535813c26c7f0b8ea011155e.camel@linaro.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/arm/mach-ep93xx/clock.c

index 85a496ddc6197e3a3d615cd9c519baeb5520af36..e9f72a529b5089b7ed2441515ee0d0fc951f126e 100644 (file)
@@ -359,7 +359,7 @@ static unsigned long ep93xx_div_recalc_rate(struct clk_hw *hw,
        u32 val = __raw_readl(psc->reg);
        u8 index = (val & psc->mask) >> psc->shift;
 
-       if (index > psc->num_div)
+       if (index >= psc->num_div)
                return 0;
 
        return DIV_ROUND_UP_ULL(parent_rate, psc->div[index]);