d5aded5479cbc8ca4188fb0d41396e788abaf2c5
[openwrt/staging/linusw.git] /
1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Bcc: linux@mail.armlinux.org.uk
3 Cc: linux-i2c@vger.kernel.org
4 Subject: [PATCH 12/17] i2c: pxa: fix i2c_pxa_wait_bus_not_busy() boundary
5 condition
6 MIME-Version: 1.0
7 Content-Disposition: inline
8 Content-Transfer-Encoding: 8bit
9 Content-Type: text/plain; charset="utf-8"
10
11 Fix i2c_pxa_wait_bus_not_busy()'s boundary conditions, so that a
12 coincidental success and timeout results in the function returning
13 success.
14
15 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
16 ---
17 drivers/i2c/busses/i2c-pxa.c | 17 ++++++++++++-----
18 1 file changed, 12 insertions(+), 5 deletions(-)
19
20 diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
21 index b2c7765756e2..19505ffbb8f1 100644
22 --- a/drivers/i2c/busses/i2c-pxa.c
23 +++ b/drivers/i2c/busses/i2c-pxa.c
24 @@ -417,19 +417,26 @@ static void i2c_pxa_abort(struct pxa_i2c *i2c)
25 static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
26 {
27 int timeout = DEF_TIMEOUT;
28 + u32 isr;
29
30 - while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
31 - if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
32 + while (1) {
33 + isr = readl(_ISR(i2c));
34 + if (!(isr & (ISR_IBB | ISR_UB)))
35 + return 0;
36 +
37 + if (isr & ISR_SAD)
38 timeout += 4;
39
40 + if (!timeout--)
41 + break;
42 +
43 msleep(2);
44 show_state(i2c);
45 }
46
47 - if (timeout < 0)
48 - show_state(i2c);
49 + show_state(i2c);
50
51 - return timeout < 0 ? I2C_RETRY : 0;
52 + return I2C_RETRY;
53 }
54
55 static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
56 --
57 2.20.1
58