Skip to content

Commit 0b884fe

Browse files
Chunyan Zhangwsakernel
authored andcommitted
i2c: sprd: use a specific timeout to avoid system hang up issue
If the i2c device SCL bus being pulled up due to some exception before message transfer done, the system cannot receive the completing interrupt signal any more, it would not exit waiting loop until MAX_SCHEDULE_TIMEOUT jiffies eclipse, that would make the system seemed hang up. To avoid that happen, this patch adds a specific timeout for message transfer. Fixes: 8b9ec07 ("i2c: Add Spreadtrum I2C controller driver") Signed-off-by: Linhua Xu <[email protected]> Signed-off-by: Chunyan Zhang <[email protected]> [wsa: changed errno to ETIMEDOUT] Signed-off-by: Wolfram Sang <[email protected]>
1 parent e71ba94 commit 0b884fe

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/i2c/busses/i2c-sprd.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
/* timeout (ms) for pm runtime autosuspend */
7474
#define SPRD_I2C_PM_TIMEOUT 1000
75+
/* timeout (ms) for transfer message */
76+
#define I2C_XFER_TIMEOUT 1000
7577

7678
/* SPRD i2c data structure */
7779
struct sprd_i2c {
@@ -244,6 +246,7 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap,
244246
struct i2c_msg *msg, bool is_last_msg)
245247
{
246248
struct sprd_i2c *i2c_dev = i2c_adap->algo_data;
249+
unsigned long time_left;
247250

248251
i2c_dev->msg = msg;
249252
i2c_dev->buf = msg->buf;
@@ -273,7 +276,10 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap,
273276

274277
sprd_i2c_opt_start(i2c_dev);
275278

276-
wait_for_completion(&i2c_dev->complete);
279+
time_left = wait_for_completion_timeout(&i2c_dev->complete,
280+
msecs_to_jiffies(I2C_XFER_TIMEOUT));
281+
if (!time_left)
282+
return -ETIMEDOUT;
277283

278284
return i2c_dev->err;
279285
}

0 commit comments

Comments
 (0)