LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Wang, Haiyue" <haiyue.wang@linux.intel.com>
To: Eduardo Valentin <eduval@amazon.com>
Cc: wsa@the-dreams.de, brendanhiggins@google.com,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	openbmc@lists.ozlabs.org, jarkko.nikula@linux.intel.com,
	andriy.shevchenko@intel.com, jae.hyun.yoo@linux.intel.com
Subject: Re: [PATCH i2c/slave-mqueue v5] i2c: slave-mqueue: add a slave backend to receive and queue messages
Date: Thu, 30 May 2019 09:39:05 +0800	[thread overview]
Message-ID: <ef5c197a-2dfc-a46c-88c2-bfec62aebeb7@linux.intel.com> (raw)
In-Reply-To: <20190529231100.GA18339@u40b0340c692b58f6553c.ant.amazon.com>


在 2019-05-30 07:11, Eduardo Valentin 写道:
>>> this code goes access and modify data here, e.g. msg->len and msg->buf.
>>>
>>> On this case (I2C_SLAVE_WRITE_RECEIVED), this code wont protect access.
>>>
>>> This can cause concurrence issues if you receive an IRQ when the user
>>> is on your bin_read().
>> User will not touch 'msg = mq->curr;', just touch 'msg =
>> &mq->queue[mq->out];'
> What happens if mq->curr == mq->queue[mq->out]?
>
1. The Read will check.

+	spin_lock_irqsave(&mq->lock, flags);
+	if (mq->out != mq->in) {
+		msg = &mq->queue[mq->out];

2. Flush the oldeast message. ^_^

+	case I2C_SLAVE_STOP:
+		if (unlikely(mq->truncated || msg->len < 2))
+			break;
+
+		spin_lock(&mq->lock);
+		mq->in = MQ_QUEUE_NEXT(mq->in);
+		mq->curr = &mq->queue[mq->in];
+		mq->curr->len = 0;
+
+		/* Flush the oldest message */
+		if (mq->out == mq->in)
+			mq->out = MQ_QUEUE_NEXT(mq->out);
+		spin_unlock(&mq->lock);



  reply	other threads:[~2019-05-30  1:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23 17:06 Haiyue Wang
2019-05-23 22:03 ` Eduardo Valentin
2019-05-24  2:43   ` Wang, Haiyue
2019-05-24 17:33     ` Eduardo Valentin
2019-05-25  5:10       ` Wang, Haiyue
2019-05-29 23:11         ` Eduardo Valentin
2019-05-30  1:39           ` Wang, Haiyue [this message]
     [not found]           ` <75cb9514-bb3a-9c3b-05df-0c3517bd775a@linux.intel.com>
2019-05-30  4:02             ` Eduardo Valentin
2019-05-30  3:13 ` Eduardo Valentin
2019-05-30  3:46 ` Eduardo Valentin
2019-05-30 17:11   ` Eduardo Valentin

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=ef5c197a-2dfc-a46c-88c2-bfec62aebeb7@linux.intel.com \
    --to=haiyue.wang@linux.intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=brendanhiggins@google.com \
    --cc=eduval@amazon.com \
    --cc=jae.hyun.yoo@linux.intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=wsa@the-dreams.de \
    --subject='Re: [PATCH i2c/slave-mqueue v5] i2c: slave-mqueue: add a slave backend to receive and queue messages' \
    /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

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).