linux-i2c.vger.kernel.org archive mirror
 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

* Re: [PATCH] i2c: stm32f7: prevent array underflow in stm32f7_get_lower_rate()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Alain Volmat @ 2020-04-29 14:15 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Pierre-Yves MORDRET, Maxime Coquelin, Alexandre Torgue,
	linux-i2c, linux-stm32, kernel-janitors, wsa, linux-arm-kernel

Hi Dan,

indeed, thanks a lot.

Reviewed-by: Alain Volmat <alain.volmat@st.com>

Alain

On Wed, Apr 29, 2020 at 04:23:23PM +0300, Dan Carpenter wrote:
> 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	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: stm32f7: prevent array underflow in stm32f7_get_lower_rate()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2020-04-30 14:07 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Pierre-Yves MORDRET, Alain Volmat, Maxime Coquelin,
	Alexandre Torgue, linux-i2c, linux-stm32, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

On Wed, Apr 29, 2020 at 04:23:23PM +0300, Dan Carpenter wrote:
> 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>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[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;
as well as URLs for NNTP newsgroup(s).