Skip to content

Commit

Permalink
i2c-pca: Fix waitforcompletion() return value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Yegor Yefremov authored and Jean Delvare committed Sep 30, 2010
1 parent 753419f commit 6abb930
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions drivers/i2c/busses/i2c-pca-isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ static int pca_isa_readbyte(void *pd, int reg)

static int pca_isa_waitforcompletion(void *pd)
{
long ret = ~0;
unsigned long timeout;
long ret;

if (irq > -1) {
ret = wait_event_timeout(pca_wait,
Expand All @@ -81,11 +81,15 @@ static int pca_isa_waitforcompletion(void *pd)
} else {
/* Do polling */
timeout = jiffies + pca_isa_ops.timeout;
while (((pca_isa_readbyte(pd, I2C_PCA_CON)
& I2C_PCA_CON_SI) == 0)
&& (ret = time_before(jiffies, timeout)))
do {
ret = time_before(jiffies, timeout);
if (pca_isa_readbyte(pd, I2C_PCA_CON)
& I2C_PCA_CON_SI)
break;
udelay(100);
} while (ret);
}

return ret > 0;
}

Expand Down
11 changes: 7 additions & 4 deletions drivers/i2c/busses/i2c-pca-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
static int i2c_pca_pf_waitforcompletion(void *pd)
{
struct i2c_pca_pf_data *i2c = pd;
long ret = ~0;
unsigned long timeout;
long ret;

if (i2c->irq) {
ret = wait_event_timeout(i2c->wait,
Expand All @@ -90,10 +90,13 @@ static int i2c_pca_pf_waitforcompletion(void *pd)
} else {
/* Do polling */
timeout = jiffies + i2c->adap.timeout;
while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
& I2C_PCA_CON_SI) == 0)
&& (ret = time_before(jiffies, timeout)))
do {
ret = time_before(jiffies, timeout);
if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
& I2C_PCA_CON_SI)
break;
udelay(100);
} while (ret);
}

return ret > 0;
Expand Down

0 comments on commit 6abb930

Please sign in to comment.