From: Wolfram Sang <wsa@kernel.org>
To: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Baolin Wang <baolin.wang7@gmail.com>,
Orson Zhai <orsonzhai@gmail.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
Chunyan Zhang <chunyan.zhang@unisoc.com>,
Linhua Xu <linhua.xu@unisoc.com>
Subject: Re: [PATCH] i2c: sprd: use a specific timeout to avoid system hang up issue
Date: Fri, 11 Dec 2020 15:53:35 +0100 [thread overview]
Message-ID: <20201211145335.GC1990@kunai> (raw)
In-Reply-To: <20201211102248.1018374-1-zhang.lyra@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]
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@unisoc.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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-12-11 15:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 10:22 [PATCH] i2c: sprd: use a specific timeout to avoid system hang up issue Chunyan Zhang
2020-12-11 14:53 ` Wolfram Sang [this message]
2020-12-11 15:42 ` kernel test robot
2020-12-11 16:46 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201211145335.GC1990@kunai \
--to=wsa@kernel.org \
--cc=baolin.wang7@gmail.com \
--cc=chunyan.zhang@unisoc.com \
--cc=linhua.xu@unisoc.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=zhang.lyra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).