i2c: stm32f7: prevent array underflow in stm32f7_get_lower_rate()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 29 Apr 2020 13:23:23 +0000 (16:23 +0300)
committerWolfram Sang <wsa@the-dreams.de>
Thu, 30 Apr 2020 14:07:14 +0000 (16:07 +0200)
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>
Reviewed-by: Alain Volmat <alain.volmat@st.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/busses/i2c-stm32f7.c

index 9c9e10ea919915722a2eb5fddc2467ea67e53bef..bff3479fe122a08fa494dbb72635b7a2fcaf5cac 100644 (file)
@@ -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;