diff options
author | Roel Kluin <roel.kluin@gmail.com> | 2009-03-28 16:34:42 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-03-28 16:34:42 -0400 |
commit | 94d78e180c0323422854bc1718e657ac2d0cac1b (patch) | |
tree | 7db1c35614e593f80ee17c10915dda76d2ee2836 /drivers/i2c | |
parent | 0c168ceb9e1898a7f2895e80ce9915835b083bd3 (diff) |
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: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Eric Brower <ebrower@gmail.com>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-pcf.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 5906986d013b..65a769f3ae79 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c | |||
@@ -115,15 +115,17 @@ static int wait_for_bb(struct i2c_algo_pcf_data *adap) | |||
115 | 115 | ||
116 | status = get_pcf(adap, 1); | 116 | status = get_pcf(adap, 1); |
117 | 117 | ||
118 | while (timeout-- && !(status & I2C_PCF_BB)) { | 118 | while (!(status & I2C_PCF_BB) && --timeout) { |
119 | udelay(100); /* wait for 100 us */ | 119 | udelay(100); /* wait for 100 us */ |
120 | status = get_pcf(adap, 1); | 120 | status = get_pcf(adap, 1); |
121 | } | 121 | } |
122 | 122 | ||
123 | if (timeout <= 0) | 123 | if (timeout == 0) { |
124 | printk(KERN_ERR "Timeout waiting for Bus Busy\n"); | 124 | printk(KERN_ERR "Timeout waiting for Bus Busy\n"); |
125 | return -ETIMEDOUT; | ||
126 | } | ||
125 | 127 | ||
126 | return timeout <= 0; | 128 | return 0; |
127 | } | 129 | } |
128 | 130 | ||
129 | static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) | 131 | 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) | |||
133 | 135 | ||
134 | *status = get_pcf(adap, 1); | 136 | *status = get_pcf(adap, 1); |
135 | 137 | ||
136 | while (timeout-- && (*status & I2C_PCF_PIN)) { | 138 | while ((*status & I2C_PCF_PIN) && --timeout) { |
137 | adap->waitforpin(adap->data); | 139 | adap->waitforpin(adap->data); |
138 | *status = get_pcf(adap, 1); | 140 | *status = get_pcf(adap, 1); |
139 | } | 141 | } |
@@ -142,10 +144,10 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) | |||
142 | return -EINTR; | 144 | return -EINTR; |
143 | } | 145 | } |
144 | 146 | ||
145 | if (timeout <= 0) | 147 | if (timeout == 0) |
146 | return -1; | 148 | return -ETIMEDOUT; |
147 | else | 149 | |
148 | return 0; | 150 | return 0; |
149 | } | 151 | } |
150 | 152 | ||
151 | /* | 153 | /* |