Skip to content

Commit

Permalink
i2c: sprd: use a specific timeout to avoid system hang up issue
Browse files Browse the repository at this point in the history
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")
Original-by: Linhua Xu <linhua.xu@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
  • Loading branch information
lyrazhang authored and intel-lab-lkp committed Dec 11, 2020
1 parent aac085f commit 725c61c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/i2c/busses/i2c-sprd.c
Expand Up @@ -72,6 +72,8 @@

/* timeout (ms) for pm runtime autosuspend */
#define SPRD_I2C_PM_TIMEOUT 1000
/* timeout (ms) for transfer message */
#define IC2_XFER_TIMEOUT 1000

/* SPRD i2c data structure */
struct sprd_i2c {
Expand Down Expand Up @@ -244,6 +246,7 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap,
struct i2c_msg *msg, bool is_last_msg)
{
struct sprd_i2c *i2c_dev = i2c_adap->algo_data;
unsigned long timeout = msecs_to_jiffies(I2C_XFER_TIMEOUT);

i2c_dev->msg = msg;
i2c_dev->buf = msg->buf;
Expand Down Expand Up @@ -273,7 +276,9 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap,

sprd_i2c_opt_start(i2c_dev);

wait_for_completion(&i2c_dev->complete);
timeout = wait_for_completion_timeout(&i2c_dev->complete, timeout);
if (!timeout)
return -EIO;

return i2c_dev->err;
}
Expand Down

0 comments on commit 725c61c

Please sign in to comment.