Skip to contentSkip to conversation

staging: sm750fb: fix unused tmp in sw_i2c_wait

PATCH Superseded Sun Jian 2 participants 6 messages Jan 5

Subsystems (3)
lore
Share & tools
lore

Sun Jian

author
#0 lore raw

PATCH 1/1 staging: sm750fb: fix unused tmp in sw_i2c_wait

clang W=1 warns that 'tmp' is set but not used in sw_i2c_wait().

Replace the dummy loop with cpu_relax() to keep the delay loop without triggering -Wunused-but-set-variable.

No functional change intended.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +4 -5
index 0ef8d4ff2ef9..279a1a10f132 100644
@@ -92,12 +92,11 @@ static void sw_i2c_wait(void)
      * it's more reliable than counter loop ..
      * write 0x61 to 0x3ce and read from 0x3cf
      */
-	int i, tmp;
+	int i;
+
+	for (i = 0; i < 600; i++)
+		cpu_relax();
 
-	for (i = 0; i < 600; i++) {
-		tmp = i;
-		tmp += i;
-	}
 }
 
 /*
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 20 lines · Sun Jian

clang W=1 warns that 'tmp' is set but not used in sw_i2c_wait().

Replace the dummy loop with cpu_relax() to keep the delay loop without triggering -Wunused-but-set-variable.

No functional change intended.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index 0ef8d4ff2ef9..279a1a10f132 100644
@@ -92,12 +92,11 @@ static void sw_i2c_wait(void)
      * it's more reliable than counter loop ..
      * write 0x61 to 0x3ce and read from 0x3cf
      */

drivers/staging/sm750fb/ddk750_swi2c.c static void sw_i2c_wait(void) · line 100

Quoted 10 lines
drivers/staging/sm750fb/ddk750_swi2c.c +4 -5
-	int i, tmp;
+	int i;
+
+	for (i = 0; i < 600; i++)
+		cpu_relax();
 
-	for (i = 0; i < 600; i++) {
-		tmp = i;
-		tmp += i;
-	}

You just slowed down this loop a lot, are you sure it still works? And really, either way, this isn't the proper way to "sleep", as it will be different speeds on different cpus/systems, and not work properly at all. Can you fix this correctly?

thanks,

greg k-h

author
#2 lore raw

PATCH v2 1/1 staging: sm750fb: fix unused tmp in sw_i2c_wait

In reply to Sun Jian

clang W=1 warns that 'tmp' is set but not used in sw_i2c_wait().

sw_i2c_wait() provides the delay between bit-banged I2C GPIO transitions. Replace the loop-count delay with a time-based udelay(1) to avoid CPU- dependent timing and fix the warning.

Compile-tested with clang W=1; no hardware available to validate timing.

---
v2:
- Replace cpu_relax() delay loop with time-based udelay(1) to avoid CPU-dependent timing (per Greg's feedback).

v1:
- Used cpu_relax() in the loop to silence -Wunused-but-set-variable.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +2 -6
index 0ef8d4ff2ef9..d5843fa69bfa 100644
@@ -11,6 +11,7 @@
 #include "ddk750_reg.h"
 #include "ddk750_swi2c.h"
 #include "ddk750_power.h"
+#include <linux/delay.h>
 
 /*
  * I2C Software Master Driver:
@@ -92,12 +93,7 @@ static void sw_i2c_wait(void)
      * it's more reliable than counter loop ..
      * write 0x61 to 0x3ce and read from 0x3cf
      */
-	int i, tmp;
-
-	for (i = 0; i < 600; i++) {
-		tmp = i;
-		tmp += i;
-	}
+	udelay(1);
 }
 
 /*
Signature · 1 line
2.43.0
maintainer
#3 lore raw
Quoted 5 lines · Sun Jian

clang W=1 warns that 'tmp' is set but not used in sw_i2c_wait().

sw_i2c_wait() provides the delay between bit-banged I2C GPIO transitions. Replace the loop-count delay with a time-based udelay(1) to avoid CPU- dependent timing and fix the warning.

Why is udelay(1) the same here?

Quoted 1 line

Compile-tested with clang W=1; no hardware available to validate timing.

That's going to prevent us from being able to take this, sorry :(

Quoted 18 lines

---
v2:
- Replace cpu_relax() delay loop with time-based udelay(1) to avoid CPU-dependent timing (per Greg's feedback).

v1:
- Used cpu_relax() in the loop to silence -Wunused-but-set-variable.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index 0ef8d4ff2ef9..d5843fa69bfa 100644

drivers/staging/sm750fb/ddk750_swi2c.c line 14

Quoted 4 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -0
@@ -11,6 +11,7 @@
 #include "ddk750_reg.h"
 #include "ddk750_swi2c.h"
 #include "ddk750_power.h"
+#include <linux/delay.h>

Shouldn't this be at the top of the include lines?

Quoted 4 lines
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
 /*
  * I2C Software Master Driver:

drivers/staging/sm750fb/ddk750_swi2c.c static void sw_i2c_wait(void) · line 96

Quoted 10 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -6
@@ -92,12 +93,7 @@ static void sw_i2c_wait(void)
      * it's more reliable than counter loop ..
      * write 0x61 to 0x3ce and read from 0x3cf
      */
-	int i, tmp;
-
-	for (i = 0; i < 600; i++) {
-		tmp = i;
-		tmp += i;
-	}
+	udelay(1);

You are ignoring the comments in this function.

Also, if you reduce this to a single call, shouldn't this whole function be removed?

thanks,

greg k-h

author
#4 lore raw

Hi Greg,

Sorry about that — I mistakenly replied only to you.

As you pointed out, sw_i2c_wait() sits on the bit-banged I2C GPIO transitions, so changing the delay semantics without hardware validation is risky. I don't have access to the hardware to validate timing/behavior, and I can't justify that udelay(1) is equivalent to the existing loop.

Please ignore v2 (and v1). I won't resend a warning-only workaround.

If someone with the hardware can help validate a proper fix (e.g. a well-justified time-based delay, or reworking this to use a proper I2C bit-banging helper), I'm happy to revisit.

Thanks,
Sun

Quoted 63 lines · Greg KH
Quoted 5 lines · Sun Jian

clang W=1 warns that 'tmp' is set but not used in sw_i2c_wait().

sw_i2c_wait() provides the delay between bit-banged I2C GPIO transitions. Replace the loop-count delay with a time-based udelay(1) to avoid CPU- dependent timing and fix the warning.

Why is udelay(1) the same here?

Quoted 1 line

Compile-tested with clang W=1; no hardware available to validate timing.

That's going to prevent us from being able to take this, sorry :(

Quoted 18 lines

---
v2:
- Replace cpu_relax() delay loop with time-based udelay(1) to avoid CPU-dependent timing (per Greg's feedback).

v1:
- Used cpu_relax() in the loop to silence -Wunused-but-set-variable.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index 0ef8d4ff2ef9..d5843fa69bfa 100644

drivers/staging/sm750fb/ddk750_swi2c.c line 14

Quoted 4 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -0
@@ -11,6 +11,7 @@
 #include "ddk750_reg.h"
 #include "ddk750_swi2c.h"
 #include "ddk750_power.h"
+#include <linux/delay.h>

Shouldn't this be at the top of the include lines?

Quoted 4 lines
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
 /*
  * I2C Software Master Driver:

drivers/staging/sm750fb/ddk750_swi2c.c static void sw_i2c_wait(void) · line 96

Quoted 10 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -6
@@ -92,12 +93,7 @@ static void sw_i2c_wait(void)
      * it's more reliable than counter loop ..
      * write 0x61 to 0x3ce and read from 0x3cf
      */
-     int i, tmp;
-
-     for (i = 0; i < 600; i++) {
-             tmp = i;
-             tmp += i;
-     }
+     udelay(1);

You are ignoring the comments in this function.

Also, if you reduce this to a single call, shouldn't this whole function be removed?

thanks,

greg k-h

maintainer
#5 lore raw
Quoted 9 lines · sun jian

Hi Greg,

Sorry about that — I mistakenly replied only to you.

As you pointed out, sw_i2c_wait() sits on the bit-banged I2C GPIO transitions, so changing the delay semantics without hardware validation is risky. I don't have access to the hardware to validate timing/behavior, and I can't justify that udelay(1) is equivalent to the existing loop.

Quoted 5 lines

Please ignore v2 (and v1). I won't resend a warning-only workaround.

If someone with the hardware can help validate a proper fix (e.g. a well-justified time-based delay, or reworking this to use a proper I2C bit-banging helper), I'm happy to revisit.

A time-based one is going to be the correct solution as every cpu will run that "let's count some numbers" loop at a different speed :(

thanks,

greg k-h