staging: sm750fb: remove ineffective sw_i2c_wait() busy loop
PATCH 1/1 staging: sm750fb: remove ineffective sw_i2c_wait() busy loop
sw_i2c_wait() is meant to insert a delay between the bit-banged I2C operations, but it only consists of a loop that computes a value into a local variable which is never read. The loop has no side effects, so the compiler removes it entirely and the function compiles to nothing. With W=1 this also triggers:
ddk750_swi2c.c:95:16: error: variable 'tmp' set but not used [-Werror=unused-but-set-variable=]
Remove the function and all of its call sites. The I2C timing is not changed by this: the object code of ddk750_swi2c.o (x86_64, gcc, allmodconfig) is identical before and after this change.
The W=1 warning was found by building the driver, and the change was prepared with the help of an AI coding assistant (Claude); it was verified by comparing the objdump output before and after the change.
--- drivers/staging/sm750fb/ddk750_swi2c.c | 34 -------------------------- 1 file changed, 34 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -34
@@ -75,31 +75,6 @@ static unsigned long sw_i2c_data_gpio_mux_reg = GPIO_MUX;static unsigned long sw_i2c_data_gpio_data_reg =GPIO_DATA ;static unsigned long sw_i2c_data_gpio_data_dir_reg =GPIO_DATA_DIRECTION ; -/* -* This function puts a delay between command -*/ -static void sw_i2c_wait (void ) -{ -/* find a bug: -* peekIO method works well before suspend/resume -* but after suspend, peekIO(0x3ce,0x61) & 0x10 -* always be non-zero,which makes the while loop -* never finish. -* use non-ultimate for loop below is safe -*/ - -/* Change wait algorithm to use PCI bus clock, -* 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; - } -} -/* * This function set/reset the SCL GPIO pin *
@@ -257,11 +232,8 @@ static long sw_i2c_write_byte(unsigned char data)else sw_i2c_sda (0 ); -sw_i2c_wait (); -/* Toggle clk line to one */ sw_i2c_scl (1 ); -sw_i2c_wait ();/* Shift byte to be sent */ value = value <<1 ;
@@ -272,9 +244,7 @@ static long sw_i2c_write_byte(unsigned char data)sw_i2c_sda (1 );/* Set the SCL High for ack */ -sw_i2c_wait ();sw_i2c_scl (1 ); -sw_i2c_wait ();/* Read SDA, until SDA==0 */ for (i =0 ; i <0xff ; i++) {
@@ -282,9 +252,7 @@ static long sw_i2c_write_byte(unsigned char data)break ;sw_i2c_scl (0 ); -sw_i2c_wait ();sw_i2c_scl (1 ); -sw_i2c_wait (); }/* Set the SCL Low and SDA High */
@@ -316,11 +284,9 @@ static unsigned char sw_i2c_read_byte(unsigned char ack)/* Set the SCL to Low and SDA to High (Input) */ sw_i2c_scl (0 );sw_i2c_sda (1 ); -sw_i2c_wait ();/* Set the SCL High */ sw_i2c_scl (1 ); -sw_i2c_wait ();/* Read data bits from SDA */ data |= (sw_i2c_read_sda () << i);
Signature · 1 line
2.56.0
Sudip, Is anyone still using this driver?
Quoted 13 lines · Leon Pelzmann
sw_i2c_wait()is meant to insert a delay between the bit-banged I2C operations, but it only consists of a loop that computes a value into a local variable which is never read. The loop has no side effects, so the compiler removes it entirely and the function compiles to nothing. With W=1 this also triggers:ddk750_swi2c.c:95:16: error: variable 'tmp' set but not used [-Werror=unused-but-set-variable=]
Remove the function and all of its call sites. The I2C timing is not changed by this: the object code of ddk750_swi2c.o (
x86_64, gcc, allmodconfig) is identical before and after this change.
Quoted 6 lines
The W=1 warning was found by building the driver, and the change was prepared with the help of an AI coding assistant (Claude); it was verified by comparing the objdump output before and after the change.
Signed-off-by Leon Pelzmann <[email protected]>---
This driver is old and when it was written the loop did add a delay. It does the silly stuff to hide that the loop is a no-op from the compiler but then compilers got clever and saw that it still a no-op.
The busy loop was added based on testing and is presumably required.
Your patch doesn't break the driver but it disguises the bug to make it look as if the driver works. We don't want that. We want the bugs to be obvious.
We have some guesses as to how to fix the driver, but actually we can't do it without testing so we are in a bind. We can't move forward without testing. To be honest, the most likely way forward is to remove the driver if no one is using it.
regards,
dan carpenter
Greg KH
maintainerQuoted 9 lines · Leon Pelzmann
sw_i2c_wait()is meant to insert a delay between the bit-banged I2C operations, but it only consists of a loop that computes a value into a local variable which is never read. The loop has no side effects, so the compiler removes it entirely and the function compiles to nothing. With W=1 this also triggers:ddk750_swi2c.c:95:16: error: variable 'tmp' set but not used [-Werror=unused-but-set-variable=]
Quoted 7 lines
Remove the function and all of its call sites. The I2C timing is not changed by this: the object code of ddk750_swi2c.o (
x86_64, gcc, allmodconfig) is identical before and after this change.The W=1 warning was found by building the driver, and the change was prepared with the help of an AI coding assistant (Claude); it was verified by comparing the objdump output before and after the change.
Please read https://lore.kernel.org/r/2026080354-skater-urgent-31b2@gregkh