diff mbox series

[1/1] i2c: observe scl_count in i2c_deblock_gpio_loop()

Message ID 20200509162018.114358-1-xypron.glpk@gmx.de
State Accepted
Commit da585c3c680add381662417b11cfc7d0ac310ba5
Headers show
Series [1/1] i2c: observe scl_count in i2c_deblock_gpio_loop() | expand

Commit Message

Heinrich Schuchardt May 9, 2020, 4:20 p.m. UTC
When compiling with -Wtype-limits we see this error:

drivers/i2c/i2c-uclass.c: In function ?i2c_deblock_gpio_loop?:
drivers/i2c/i2c-uclass.c:517:21: error: comparison of
unsigned expression >= 0 is always true [-Werror=type-limits]
  517 |  while (scl_count-- >= 0) {
      |

Don't loop forever.

Fixes: 1f746a2c82b1 ("i2c: Make deblock delay and SCL clock configurable")
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 drivers/i2c/i2c-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.26.2

Comments

Heiko Schocher May 30, 2020, 3:50 a.m. UTC | #1
Hello Heinrich,

Am 09.05.2020 um 18:20 schrieb Heinrich Schuchardt:
> When compiling with -Wtype-limits we see this error:
> 
> drivers/i2c/i2c-uclass.c: In function ?i2c_deblock_gpio_loop?:
> drivers/i2c/i2c-uclass.c:517:21: error: comparison of
> unsigned expression >= 0 is always true [-Werror=type-limits]
>    517 |  while (scl_count-- >= 0) {
>        |
> 
> Don't loop forever.
> 
> Fixes: 1f746a2c82b1 ("i2c: Make deblock delay and SCL clock configurable")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
>   drivers/i2c/i2c-uclass.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-i2c master

Thanks!

bye,
Heiko
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index e9ec388576..9b2727cfd8 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -514,7 +514,7 @@  int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin,
 	udelay(delay);

 	/*  Toggle SCL until slave release SDA */
-	while (scl_count-- >= 0) {
+	for (; scl_count; --scl_count) {
 		i2c_gpio_set_pin(scl_pin, 1);
 		udelay(delay);
 		i2c_gpio_set_pin(scl_pin, 0);