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

Commit 94d78e18 authored by Roel Kluin's avatar Roel Kluin Committed by Jean Delvare
Browse files

i2c-algo-pcf: Handle timeout correctly



With a postfix decrement these timeouts reach -1 rather than 0, but after the
loop it is tested whether they have become 0.

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.

Signed-off-by: default avatarRoel Kluin <roel.kluin@gmail.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarEric Brower <ebrower@gmail.com>
parent 0c168ceb
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -115,15 +115,17 @@ static int wait_for_bb(struct i2c_algo_pcf_data *adap)

	status = get_pcf(adap, 1);

	while (timeout-- && !(status & I2C_PCF_BB)) {
	while (!(status & I2C_PCF_BB) && --timeout) {
		udelay(100); /* wait for 100 us */
		status = get_pcf(adap, 1);
	}

	if (timeout <= 0)
	if (timeout == 0) {
		printk(KERN_ERR "Timeout waiting for Bus Busy\n");
		return -ETIMEDOUT;
	}

	return timeout <= 0;
	return 0;
}

static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
@@ -133,7 +135,7 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)

	*status = get_pcf(adap, 1);

	while (timeout-- && (*status & I2C_PCF_PIN)) {
	while ((*status & I2C_PCF_PIN) && --timeout) {
		adap->waitforpin(adap->data);
		*status = get_pcf(adap, 1);
	}
@@ -142,9 +144,9 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
		return -EINTR;
	}

	if (timeout <= 0)
		return -1;
	else
	if (timeout == 0)
		return -ETIMEDOUT;

	return 0;
}