From: Che-liang Chiou <clchiou@chromium.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org,
Wanlong Gao <gaowanlong@cn.fujitsu.com>,
David Herrmann <dh.herrmann@googlemail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: serio_raw - ensure we don't block in non-blocking read
Date: Tue, 17 Apr 2012 17:14:44 +0800 [thread overview]
Message-ID: <CANJuy2KVxAKFETi4YGAcBFnoop-eBLK+VvUVonuy8ZCm+VeZcg@mail.gmail.com> (raw)
In-Reply-To: <CANJuy2KgOX=2Oc9Uaf1TGRAeyXt0UjdjU-o-yo+NVUYxKmk_4g@mail.gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 3700 bytes --]
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
On Tue, Apr 17, 2012 at 4:56 PM, Che-liang Chiou <clchiou@chromium.org> wrote:
> I didn't test the patch, but the logic looks fine to me.
>
> On Wed, Apr 4, 2012 at 4:24 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>> Avoid calling wait_event_interruptible() if client requested non-blocking
>> read, since it is not guaranteed that another thread will not consume
>> event after we checked if serio_raw->head != serio_raw->tail.
>>
>> Also ensure we do not return 0 but keep waiting instead in blocking case,
>> when another thread steals "our" byte.
>>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>> Â drivers/input/serio/serio_raw.c | Â 43 ++++++++++++++++++++++----------------
>> Â 1 files changed, 25 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
>> index 4494233..094d6fb 100644
>> --- a/drivers/input/serio/serio_raw.c
>> +++ b/drivers/input/serio/serio_raw.c
>> @@ -165,31 +165,38 @@ static ssize_t serio_raw_read(struct file *file, char __user *buffer,
>> Â Â Â Â struct serio_raw *serio_raw = client->serio_raw;
>> Â Â Â Â char uninitialized_var(c);
>> Â Â Â Â ssize_t read = 0;
>> - Â Â Â int retval;
>> + Â Â Â int error = 0;
>>
>> - Â Â Â if (serio_raw->dead)
>> - Â Â Â Â Â Â Â return -ENODEV;
>> + Â Â Â do {
>> + Â Â Â Â Â Â Â if (serio_raw->dead)
>> + Â Â Â Â Â Â Â Â Â Â Â return -ENODEV;
>>
>> - Â Â Â if (serio_raw->head == serio_raw->tail && (file->f_flags & O_NONBLOCK))
>> - Â Â Â Â Â Â Â return -EAGAIN;
>> + Â Â Â Â Â Â Â if (serio_raw->head == serio_raw->tail &&
>> + Â Â Â Â Â Â Â Â Â (file->f_flags & O_NONBLOCK))
>> + Â Â Â Â Â Â Â Â Â Â Â return -EAGAIN;
>>
>> - Â Â Â retval = wait_event_interruptible(serio_raw->wait,
>> - Â Â Â Â Â Â Â Â Â Â Â serio_raw->head != serio_raw->tail || serio_raw->dead);
>> - Â Â Â if (retval)
>> - Â Â Â Â Â Â Â return retval;
>> + Â Â Â Â Â Â Â if (count == 0)
>> + Â Â Â Â Â Â Â Â Â Â Â break;
>>
>> - Â Â Â if (serio_raw->dead)
>> - Â Â Â Â Â Â Â return -ENODEV;
>> + Â Â Â Â Â Â Â while (read < count && serio_raw_fetch_byte(serio_raw, &c)) {
>> + Â Â Â Â Â Â Â Â Â Â Â if (put_user(c, buffer++)) {
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â error = -EFAULT;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
>> + Â Â Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â Â Â Â Â read++;
>> + Â Â Â Â Â Â Â }
>>
>> - Â Â Â while (read < count && serio_raw_fetch_byte(serio_raw, &c)) {
>> - Â Â Â Â Â Â Â if (put_user(c, buffer++)) {
>> - Â Â Â Â Â Â Â Â Â Â Â retval = -EFAULT;
>> + Â Â Â Â Â Â Â if (read)
>> Â Â Â Â Â Â Â Â Â Â Â Â break;
>> - Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â read++;
>> - Â Â Â }
>>
>> - Â Â Â return read ?: retval;
>> + Â Â Â Â Â Â Â if (!(file->f_flags & O_NONBLOCK))
>> + Â Â Â Â Â Â Â Â Â Â Â error = wait_event_interruptible(serio_raw->wait,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â serio_raw->head != serio_raw->tail ||
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â serio_raw->dead);
>> + Â Â Â } while (!error);
>> +
>> +out:
>> + Â Â Â return read ?: error;
>> Â }
>>
>> Â static ssize_t serio_raw_write(struct file *file, const char __user *buffer,
>> --
>> 1.7.7.6
>>
>>
>> --
>> Dmitry
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
prev parent reply other threads:[~2012-04-17 9:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 20:24 [PATCH] Input: serio_raw - ensure we don't block in non-blocking read Dmitry Torokhov
2012-04-11 7:23 ` Dmitry Torokhov
2012-04-13 16:50 ` David Herrmann
2012-04-17 8:56 ` Che-liang Chiou
2012-04-17 9:14 ` Che-liang Chiou [this message]
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=CANJuy2KVxAKFETi4YGAcBFnoop-eBLK+VvUVonuy8ZCm+VeZcg@mail.gmail.com \
--to=clchiou@chromium.org \
--cc=dh.herrmann@googlemail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gaowanlong@cn.fujitsu.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).