Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6abb930a authored by Yegor Yefremov's avatar Yegor Yefremov Committed by Jean Delvare
Browse files

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: default avatarYegor Yefremov <yegorslists@googlemail.com>
Reviewed-by: default avatarWolfram Sang <w.sang@pengutronix.de>
Cc: stable@kernel.org
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 753419f5
Loading
Loading
Loading
Loading
+8 −4
Original line number Original line Diff line number Diff line
@@ -71,8 +71,8 @@ static int pca_isa_readbyte(void *pd, int reg)


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


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

	return ret > 0;
	return ret > 0;
}
}


+7 −4
Original line number Original line Diff line number Diff line
@@ -80,8 +80,8 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
static int i2c_pca_pf_waitforcompletion(void *pd)
static int i2c_pca_pf_waitforcompletion(void *pd)
{
{
	struct i2c_pca_pf_data *i2c = pd;
	struct i2c_pca_pf_data *i2c = pd;
	long ret = ~0;
	unsigned long timeout;
	unsigned long timeout;
	long ret;


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


	return ret > 0;
	return ret > 0;