[PATCH] clk: ux500: fix a possible off-by-one in u8500_prcc_reset_base()

Hangyu Hua posted 1 patch 3 years, 11 months ago
drivers/clk/ux500/reset-prcc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] clk: ux500: fix a possible off-by-one in u8500_prcc_reset_base()
Posted by Hangyu Hua 3 years, 11 months ago
Off-by-one will happen when index == ARRAY_SIZE(ur->base).

Fixes: b14cbdfd467d ("clk: ux500: Add driver for the reset portions of PRCC")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/clk/ux500/reset-prcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/ux500/reset-prcc.c b/drivers/clk/ux500/reset-prcc.c
index fcd5d042806a..f7e48941fbc7 100644
--- a/drivers/clk/ux500/reset-prcc.c
+++ b/drivers/clk/ux500/reset-prcc.c
@@ -58,7 +58,7 @@ static void __iomem *u8500_prcc_reset_base(struct u8500_prcc_reset *ur,
 	prcc_num = id / PRCC_PERIPHS_PER_CLUSTER;
 	index = prcc_num_to_index(prcc_num);
 
-	if (index > ARRAY_SIZE(ur->base))
+	if (index >= ARRAY_SIZE(ur->base))
 		return NULL;
 
 	return ur->base[index];
-- 
2.25.1
Re: [PATCH] clk: ux500: fix a possible off-by-one in u8500_prcc_reset_base()
Posted by Stephen Boyd 3 years, 11 months ago
Quoting Hangyu Hua (2022-05-17 23:25:37)
> Off-by-one will happen when index == ARRAY_SIZE(ur->base).
> 
> Fixes: b14cbdfd467d ("clk: ux500: Add driver for the reset portions of PRCC")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---

Applied to clk-next
Re: [PATCH] clk: ux500: fix a possible off-by-one in u8500_prcc_reset_base()
Posted by Linus Walleij 3 years, 11 months ago
On Wed, May 18, 2022 at 8:25 AM Hangyu Hua <hbh25y@gmail.com> wrote:

> Off-by-one will happen when index == ARRAY_SIZE(ur->base).
>
> Fixes: b14cbdfd467d ("clk: ux500: Add driver for the reset portions of PRCC")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>

Good catch!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij