i2c: timeouts reach -1
PATCH 1/1 i2c: timeouts reach -1
With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0.
--- drivers/i2c/busses/i2c-amd8111.c | 4 ++-- drivers/i2c/busses/i2c-pxa.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-amd8111.c +2 -2
@@ -72,7 +72,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF )) +while (--timeout && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF ))udelay (1 );if (!timeout) {
@@ -88,7 +88,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF )) +while (--timeout && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF ))udelay (1 );if (!timeout) {
drivers/i2c/busses/i2c-pxa.c +1 -1
@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (--timeout && i2c->msg_num >0 ) {i2c_pxa_handler (0 , i2c);udelay (10 ); }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Roel,
Quoted 36 lines · Roel Kluin
With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0.
Signed-off-by Roel Kluin <[email protected]>--- drivers/i2c/busses/i2c-amd8111.c | 4 ++-- drivers/i2c/busses/i2c-pxa.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-amd8111.c +2
-2@@ -72,7 +72,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF )) +while (--timeout && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF ))udelay (1 );if (!timeout) {@@ -88,7 +88,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF )) +while (--timeout && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF ))udelay (1 );if (!timeout) {drivers/i2c/busses/i2c-pxa.c +0
-0
drivers/i2c/busses/i2c-pxa.c static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, · line 650
Quoted 8 lines
drivers/i2c/busses/i2c-pxa.c +1
-1@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (--timeout && i2c->msg_num >0 ) {i2c_pxa_handler (0 , i2c);udelay (10 ); }
Good catch. Applied, thanks for reporting.
Signature · 1 line
Jean Delvare
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 16 lines · Jean Delvare
Hi Roel,
Quoted 13 lines · Roel Kluin
With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0.
Signed-off-by Roel Kluin <[email protected]>(...)
drivers/i2c/busses/i2c-pxa.c +0
-0@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,i2c_pxa_start_message (i2c);
Quoted 7 lines
drivers/i2c/busses/i2c-pxa.c static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, · line 650
Quoted 5 lines
drivers/i2c/busses/i2c-pxa.c +1
-1-while (timeout-- && i2c->msg_num >0 ) { +while (--timeout && i2c->msg_num >0 ) {i2c_pxa_handler (0 , i2c);udelay (10 ); }Good catch. Applied, thanks for reporting.
On second thought, shouldn't the msg_num test be done first and the timeout test second? With the current order, you could exit with a timeout error while all the messages were successfully transferred.
Signature · 1 line
Jean Delvare
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 24 lines · Jean Delvare
Quoted 14 lines · Jean Delvare
Hi Roel,
Quoted 11 lines · Roel Kluin
With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0.
Signed-off-by Roel Kluin <[email protected]>(...)
drivers/i2c/busses/i2c-pxa.c +0
-0@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,Quoted 8 lines
drivers/i2c/busses/i2c-pxa.c static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, · line 650
Quoted 7 lines
drivers/i2c/busses/i2c-pxa.c +1
-1i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (--timeout && i2c->msg_num >0 ) {i2c_pxa_handler (0 , i2c);udelay (10 ); }Good catch. Applied, thanks for reporting.
Quoted 3 lines
On second thought, shouldn't the
msg_numtest be done first and the timeout test second? With the current order, you could exit with a timeout error while all the messages were successfully transferred.
Thanks again for the review, How about:
----------------------------->8-----------------8<------------------------------ With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0. also test before the decrement
As pointed out by Jean Delvare, the msg_num should be tested before the timeout. With the current order, you could exit with a timeout error while all the messages were successfully transferred.
---
drivers/i2c/busses/i2c-amd8111.c +4 -4
@@ -72,10 +72,10 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF )) +while ((inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF ) && --timeout)udelay (1 ); -if (!timeout) { +if (timeout <=0 ) {dev_warn (&smbus->dev->dev,"Timeout while waiting for IBF to clear\n" );return -ETIMEDOUT ;
@@ -88,10 +88,10 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF )) +while ((~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF ) && --timeout)udelay (1 ); -if (!timeout) { +if (timeout <=0 ) {dev_warn (&smbus->dev->dev,"Timeout while waiting for OBF to set\n" );return -ETIMEDOUT ;
drivers/i2c/busses/i2c-pxa.c +2 -2
@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (i2c->msg_num >0 && --timeout) {i2c_pxa_handler (0 , i2c);udelay (10 ); }
@@ -657,7 +657,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, ret = i2c->msg_idx; out: -if (timeout ==0 ) +if (timeout <=0 )i2c_pxa_scream_blue_murder (i2c,"timeout" );return ret;
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 46 lines · Roel Kluin
Quoted 24 lines · Jean Delvare
Quoted 14 lines · Jean Delvare
Hi Roel,
Quoted 11 lines · Roel Kluin
With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0.
Signed-off-by Roel Kluin <[email protected]>(...)
drivers/i2c/busses/i2c-pxa.c +0
-0@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,Quoted 8 lines
drivers/i2c/busses/i2c-pxa.c static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, · line 650
Quoted 7 lines
drivers/i2c/busses/i2c-pxa.c +1
-1i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (--timeout && i2c->msg_num >0 ) {i2c_pxa_handler (0 , i2c);udelay (10 ); }Good catch. Applied, thanks for reporting.
Quoted 3 lines
On second thought, shouldn't the
msg_numtest be done first and the timeout test second? With the current order, you could exit with a timeout error while all the messages were successfully transferred.Thanks again for the review, How about:
----------------------------->8-----------------8<------------------------------ With a postfix decrement these timeouts reach -1 rather than 0, but after the loop it is tested whether they have become 0. also test before the decrement
As pointed out by Jean Delvare, the
msg_numshould be tested before the timeout. With the current order, you could exit with a timeout error while all the messages were successfully transferred.Signed-off-by Roel Kluin <[email protected]>---
drivers/i2c/busses/i2c-amd8111.c +0
-0
drivers/i2c/busses/i2c-amd8111.c static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) · line 78
Quoted 9 lines
drivers/i2c/busses/i2c-amd8111.c +2
-2@@ -72,10 +72,10 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF )) +while ((inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_IBF ) && --timeout)udelay (1 ); -if (!timeout) { +if (timeout <=0 ) {
See my previous mail: you're trying to fix up the confusion regarding the value of timeout at the end of the loop. Changing the decrement from postfix to prefix is sufficient to solve the issue. Changing the test from == 0 to <= 0 is also sufficient. Doing both is redundant _and_ fails to clear the confusion. The resulting code makes it look like timeout _may_ become negative, which is not true.
So, I intend to keep only the first half of each fix, and apply that.
Quoted 38 lines
drivers/i2c/busses/i2c-amd8111.c +2
-2dev_warn (&smbus->dev->dev,"Timeout while waiting for IBF to clear\n" );return -ETIMEDOUT ;@@ -88,10 +88,10 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) {int timeout =500 ; -while (timeout-- && (~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF )) +while ((~inb (smbus->base +AMD_EC_SC ) &AMD_EC_SC_OBF ) && --timeout)udelay (1 ); -if (!timeout) { +if (timeout <=0 ) {dev_warn (&smbus->dev->dev,"Timeout while waiting for OBF to set\n" );return -ETIMEDOUT ;drivers/i2c/busses/i2c-pxa.c +2
-2@@ -644,7 +644,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,i2c_pxa_start_message (i2c); -while (timeout-- && i2c->msg_num >0 ) { +while (i2c->msg_num >0 && --timeout) {i2c_pxa_handler (0 , i2c);udelay (10 ); }@@ -657,7 +657,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, ret = i2c->msg_idx; out: -if (timeout ==0 ) +if (timeout <=0 )i2c_pxa_scream_blue_murder (i2c,"timeout" );return ret;
Signature · 1 line
Jean Delvare