[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201211145335.GC1990@kunai>
Date: Fri, 11 Dec 2020 15:53:35 +0100
From: Wolfram Sang <wsa@...nel.org>
To: Chunyan Zhang <zhang.lyra@...il.com>
Cc: Baolin Wang <baolin.wang7@...il.com>,
Orson Zhai <orsonzhai@...il.com>, linux-i2c@...r.kernel.org,
linux-kernel@...r.kernel.org,
Chunyan Zhang <chunyan.zhang@...soc.com>,
Linhua Xu <linhua.xu@...soc.com>
Subject: Re: [PATCH] i2c: sprd: use a specific timeout to avoid system hang
up issue
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@...soc.com>
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
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists