Re: [PATCH] i2c: sprd: use a specific timeout to avoid system hang up issue
From: Wolfram Sang
Date: Fri Dec 11 2020 - 10:06:33 EST
Hi,
thanks for your patch!
> 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.
Yes.
> Fixes: 8b9ec0719834 ("i2c: Add Spreadtrum I2C controller driver")
> Original-by: Linhua Xu <linhua.xu@xxxxxxxxxx>
I can't find this tag documented. Maybe "Co-developed by"? Or just
"Signed-off-by"?
> + unsigned long timeout = msecs_to_jiffies(I2C_XFER_TIMEOUT);
>
> i2c_dev->msg = msg;
> i2c_dev->buf = msg->buf;
> @@ -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;
Basically OK, but readability can be improved. Because it reads "if not
timeout, then return error". But it IS a timeout :) What about this:
time_left = wait_for_completion_timeout(&i2c_dev->complete,
msecs_to_jiffies(I2C_XFER_TIMEOUT));
if (!time_left)
...
and the rest adjusted accordingly. What do you think?
Kind regards,
Wolfram
Attachment:
signature.asc
Description: PGP signature