aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVille Syrjala <syrjala@sci.fi>2012-03-15 13:11:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-03-19 11:57:59 -0400
commit35f68010b4311eacf6340473b062418715d68a39 (patch)
treecb482f2b882598f145a2643bbee9e9e20ddfbbcd
parent90b7d65c8cba8830ede8307a21a76c8757eefa3a (diff)
i2c-algo-bit: Fix spurious SCL timeouts under heavy load
commit 8ee161ce5e0cfc689eb677f227a6248191165fac upstream. When the system is under heavy load, there can be a significant delay between the getscl() and time_after() calls inside sclhi(). That delay may cause the time_after() check to trigger after SCL has gone high, causing sclhi() to return -ETIMEDOUT. To fix the problem, double check that SCL is still low after the timeout has been reached, before deciding to return -ETIMEDOUT. Signed-off-by: Ville Syrjala <syrjala@sci.fi> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index eca3bcc4599..f2ce8c36816 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -103,8 +103,14 @@ static int sclhi(struct i2c_algo_bit_data *adap)
103 * chips may hold it low ("clock stretching") while they 103 * chips may hold it low ("clock stretching") while they
104 * are processing data internally. 104 * are processing data internally.
105 */ 105 */
106 if (time_after(jiffies, start + adap->timeout)) 106 if (time_after(jiffies, start + adap->timeout)) {
107 /* Test one last time, as we may have been preempted
108 * between last check and timeout test.
109 */
110 if (getscl(adap))
111 break;
107 return -ETIMEDOUT; 112 return -ETIMEDOUT;
113 }
108 cond_resched(); 114 cond_resched();
109 } 115 }
110#ifdef DEBUG 116#ifdef DEBUG