All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ep93xx: clock: Fix off by one in ep93xx_div_recalc_rate()
@ 2024-09-11  7:39 Dan Carpenter
  2024-09-11  7:52 ` Alexander Sverdlin
  2024-09-11  8:14 ` Nikita Shubin
  0 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-09-11  7:39 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Hartley Sweeten, Alexander Sverdlin, Russell King, Arnd Bergmann,
	linux-arm-kernel, linux-kernel, kernel-janitors

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>
---
 arch/arm/mach-ep93xx/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c
index 85a496ddc619..e9f72a529b50 100644
--- a/arch/arm/mach-ep93xx/clock.c
+++ b/arch/arm/mach-ep93xx/clock.c
@@ -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]);
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] ep93xx: clock: Fix off by one in ep93xx_div_recalc_rate()
@ 2024-09-11  7:39 Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-09-11  7:39 UTC (permalink / raw)
  To: soc

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>

---
 arch/arm/mach-ep93xx/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c
index 85a496ddc619..e9f72a529b50 100644
--- a/arch/arm/mach-ep93xx/clock.c
+++ b/arch/arm/mach-ep93xx/clock.c
@@ -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]);
-- 
2.46.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-09-11 16:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11  7:39 [PATCH] ep93xx: clock: Fix off by one in ep93xx_div_recalc_rate() Dan Carpenter
2024-09-11  7:52 ` Alexander Sverdlin
2024-09-11  8:14 ` Nikita Shubin
2024-09-11 14:54   ` Arnd Bergmann
2024-09-11 14:59     ` Alexander Sverdlin
2024-09-11 16:28       ` Nikita Shubin
  -- strict thread matches above, loose matches on Subject: below --
2024-09-11  7:39 Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.