Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c-pca: Fix waitforcompletion() return value

ret is still -1, if during the polling read_byte() returns at once
with I2C_PCA_CON_SI set. So ret > 0 would lead *_waitforcompletion()
to return 0, in spite of the proper behavior.

The routine was rewritten, so that ret has always a proper value,
before returning.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Reviewed-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: stable@kernel.org
Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by

Yegor Yefremov and committed by
Jean Delvare
6abb930a 753419f5

+15 -8
+8 -4
drivers/i2c/busses/i2c-pca-isa.c
··· 71 71 72 72 static int pca_isa_waitforcompletion(void *pd) 73 73 { 74 - long ret = ~0; 75 74 unsigned long timeout; 75 + long ret; 76 76 77 77 if (irq > -1) { 78 78 ret = wait_event_timeout(pca_wait, ··· 81 81 } else { 82 82 /* Do polling */ 83 83 timeout = jiffies + pca_isa_ops.timeout; 84 - while (((pca_isa_readbyte(pd, I2C_PCA_CON) 85 - & I2C_PCA_CON_SI) == 0) 86 - && (ret = time_before(jiffies, timeout))) 84 + do { 85 + ret = time_before(jiffies, timeout); 86 + if (pca_isa_readbyte(pd, I2C_PCA_CON) 87 + & I2C_PCA_CON_SI) 88 + break; 87 89 udelay(100); 90 + } while (ret); 88 91 } 92 + 89 93 return ret > 0; 90 94 } 91 95
+7 -4
drivers/i2c/busses/i2c-pca-platform.c
··· 80 80 static int i2c_pca_pf_waitforcompletion(void *pd) 81 81 { 82 82 struct i2c_pca_pf_data *i2c = pd; 83 - long ret = ~0; 84 83 unsigned long timeout; 84 + long ret; 85 85 86 86 if (i2c->irq) { 87 87 ret = wait_event_timeout(i2c->wait, ··· 90 90 } else { 91 91 /* Do polling */ 92 92 timeout = jiffies + i2c->adap.timeout; 93 - while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) 94 - & I2C_PCA_CON_SI) == 0) 95 - && (ret = time_before(jiffies, timeout))) 93 + do { 94 + ret = time_before(jiffies, timeout); 95 + if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON) 96 + & I2C_PCA_CON_SI) 97 + break; 96 98 udelay(100); 99 + } while (ret); 97 100 } 98 101 99 102 return ret > 0;