Skip to content

Commit 8ee161c

Browse files
syrjalaJean Delvare
authored andcommitted
i2c-algo-bit: Fix spurious SCL timeouts under heavy load
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> Cc: stable@vger.kernel.org Signed-off-by: Jean Delvare <khali@linux-fr.org>
1 parent 834aa6f commit 8ee161c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/i2c/algos/i2c-algo-bit.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ static int sclhi(struct i2c_algo_bit_data *adap)
103103
* chips may hold it low ("clock stretching") while they
104104
* are processing data internally.
105105
*/
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;
107112
return -ETIMEDOUT;
113+
}
108114
cond_resched();
109115
}
110116
#ifdef DEBUG

0 commit comments

Comments
 (0)