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: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Eric Brower <ebrower@gmail.com>
status = get_pcf(adap, 1);
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);
}
udelay(100); /* wait for 100 us */
status = get_pcf(adap, 1);
}
printk(KERN_ERR "Timeout waiting for Bus Busy\n");
printk(KERN_ERR "Timeout waiting for Bus Busy\n");
}
static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
}
static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
*status = get_pcf(adap, 1);
*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);
}
adap->waitforpin(adap->data);
*status = get_pcf(adap, 1);
}
- if (timeout <= 0)
- return -1;
- else
- return 0;
+ if (timeout == 0)
+ return -ETIMEDOUT;
+
+ return 0;