public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: stm32f7: prevent array underflow in stm32f7_get_lower_rate()
@ 2020-04-29 13:23 Dan Carpenter
  2020-04-29 14:15 ` Alain Volmat
  2020-04-30 14:07 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-04-29 13:23 UTC (permalink / raw)
  To: Pierre-Yves MORDRET, Alain Volmat
  Cc: Maxime Coquelin, Alexandre Torgue, linux-i2c, linux-stm32,
	kernel-janitors

We want to break with "i" set to zero whether we find the rate we want
or not.  In the current code, if we don't find the rate we want then it
exits the loop with "i" set to -1 and results in an array underflow.

Fixes: 09cc9a3bce91 ("i2c: stm32f7: allows for any bus frequency")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/i2c/busses/i2c-stm32f7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 9c9e10ea91991..bff3479fe122a 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -607,7 +607,7 @@ static u32 stm32f7_get_lower_rate(u32 rate)
 {
 	int i = ARRAY_SIZE(stm32f7_i2c_specs);
 
-	while (i--)
+	while (--i)
 		if (stm32f7_i2c_specs[i].rate < rate)
 			break;
 
-- 
2.26.2


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

end of thread, other threads:[~2020-04-30 14:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-29 13:23 [PATCH] i2c: stm32f7: prevent array underflow in stm32f7_get_lower_rate() Dan Carpenter
2020-04-29 14:15 ` Alain Volmat
2020-04-30 14:07 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox