public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: HansHu-oc <HansHu-oc@zhaoxin.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: "jdelvare@suse.com" <jdelvare@suse.com>,
	"wsa@kernel.org" <wsa@kernel.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	"Cobe Chen(BJ-RD)" <CobeChen@zhaoxin.com>,
	"Tony W. Wang(XA-RD)" <TonyWWang@zhaoxin.com>
Subject: Re: [PATCH v2] i2c: add support for Zhaoxin I2C controller
Date: Thu, 1 Jun 2023 06:37:56 +0000	[thread overview]
Message-ID: <3509ba04d98b4537ba3459407da43f62@zhaoxin.com> (raw)

Hi Andi,

Thank you very much for reviewing this. I'll take most of your
proposed changes and double check patch with checkpatch.pl.

For the following two proposed changes, please see if my
consideration is reasonable.

On 2023/5/31 19:00, Andi Shyti wrote:
> [...]
>
>> +static irqreturn_t zxi2c_irq_handle(int irq, void *dev_id)
>> +{
>> +	struct zxi2c *i2c = (struct zxi2c *)dev_id;
>> +	void __iomem *regs = i2c->regs;
>> +	u8 status = get_irq_status(regs);
>> +
>> +	if ((status & IRQ_STS_MASK) == 0)
>> +		return IRQ_NONE;
>
> unlikely?

This irq is shared, so it is possible.

>> +	if (status & IRQ_SCL_TIMEOUT)
>> +		dev_warn(i2c->dev, "timeout(HW), ID: 0x%X\n", i2c->addr);
>> +
>> +	if (status & IRQ_STS_ADDRNACK) {
>> +		dev_dbg(i2c->dev, "addr NACK, ID: 0x%X\n", i2c->addr);
>> +	} else if (status & IRQ_STS_BYTEEND) {
>> +		i2c->byte_left--;
>> +		if (!i2c->is_read) {
>> +			if (is_nack(regs)) {
>> +				status = IRQ_STS_BYTENACK;
>> +				i2c->byte_left++;
>> +				dev_err(i2c->dev, "data NACK, ID: 0x%X\n",
>> +					i2c->addr);
>> +			} else if (i2c->byte_left == 0 && i2c->is_last_msg) {
>> +				stop_write_byte(regs);
>> +			}
>> +		}
>> +	}
>> +
>> +	i2c->event = status;
>> +	clear_irq_status(regs);
>> +	wake_up(&i2c->waitq);
>> +
>> +	return IRQ_HANDLED;
>> +}
>> +
>> +static int zxi2c_wait_event(struct zxi2c *i2c, u8 event)
>> +{
>> +	int timeout;
>> +
>> +	timeout = wait_event_interruptible_timeout(i2c->waitq,
>> +			i2c->event != 0,
>> +			msecs_to_jiffies(ZXI2C_TIMEOUT));
>> +
>> +	if (i2c->event & event)
>> +		return 0;
>
> is this valid even when "timeout == 0"?

Let's see the description of the value returned by wait_event_interruptible_timeout():
https://elixir.bootlin.com/linux/v6.3.5/source/include/linux/wait.h#L525
 * Returns:
 * 0 if the @condition evaluated to %false after the @timeout elapsed,
 * 1 if the @condition evaluated to %true after the @timeout elapsed,
 * the remaining jiffies (at least 1) if the @condition evaluated
 * to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
 * interrupted by a signal.
So, "timeout == 0" and @condition evaluated to %true unlikely to happen at the same time.

Or is it OK to change it to like below?
+    timeout = wait_event_interruptible_timeout(i2c->waitq,
+            i2c->event != 0,
+            msecs_to_jiffies(ZXI2C_TIMEOUT));
+
+    if (i2c->event & event) {
+        if (timeout == 1)
+            dev_warn(i2c->dev, "thread may be blocked\n");
+        return 0;
+    }
+
+    if (timeout == 0) {

Hans

             reply	other threads:[~2023-06-01  6:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01  6:37 HansHu-oc [this message]
2023-06-01  9:31 ` [PATCH v2] i2c: add support for Zhaoxin I2C controller Andi Shyti
  -- strict thread matches above, loose matches on Subject: below --
2023-05-29  7:31 Hans Hu
2023-05-31 11:00 ` Andi Shyti

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=3509ba04d98b4537ba3459407da43f62@zhaoxin.com \
    --to=hanshu-oc@zhaoxin.com \
    --cc=CobeChen@zhaoxin.com \
    --cc=TonyWWang@zhaoxin.com \
    --cc=andi.shyti@kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@kernel.org \
    /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