<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<div class="moz-cite-prefix">在 2019-05-30 07:11, Eduardo Valentin
写道:<br>
</div>
<blockquote type="cite"
cite="mid:20190529231100.GA18339@u40b0340c692b58f6553c.ant.amazon.com">
<blockquote type="cite" style="color: #000000;">
<blockquote type="cite" style="color: #000000;">
<pre class="moz-quote-pre" wrap="">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().
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">User will not touch 'msg = mq->curr;', just touch 'msg =
&mq->queue[mq->out];'
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
What happens if mq->curr == mq->queue[mq->out]?
</pre>
</blockquote>
<br>
<p>1. The Read will check.<br>
</p>
<pre class="moz-quote-pre" wrap="">+ 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);</pre>
<blockquote type="cite"
cite="mid:20190529231100.GA18339@u40b0340c692b58f6553c.ant.amazon.com">
<pre class="moz-quote-pre" wrap="">
</pre>
</blockquote>
</body>
</html>