Input: evdev - do not block waiting for an event if fd is nonblock
authorDima Zavin <dima@android.com>
Fri, 30 Dec 2011 23:16:44 +0000 (15:16 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 30 Dec 2011 23:26:35 +0000 (15:26 -0800)
If there is a full packet in the buffer, and we overflow that buffer
right after checking for that condition, it would have been possible
for us to block indefinitely (rather, until the next full packet) even if
the file was marked as O_NONBLOCK.

Cc: Jeff Brown <jeffbrown@android.com>
Signed-off-by: Dima Zavin <dima@android.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/input/evdev.c

index a9d871651ce70e5a1f6288b2343b240e599de3b2..76457d50bc3493e351c40fbe5b667d1b2e33ff6a 100644 (file)
@@ -391,14 +391,13 @@ static ssize_t evdev_read(struct file *file, char __user *buffer,
        if (count < input_event_size())
                return -EINVAL;
 
-       if (client->packet_head == client->tail && evdev->exist &&
-           (file->f_flags & O_NONBLOCK))
-               return -EAGAIN;
-
-       retval = wait_event_interruptible(evdev->wait,
-               client->packet_head != client->tail || !evdev->exist);
-       if (retval)
-               return retval;
+       if (!(file->f_flags & O_NONBLOCK)) {
+               retval = wait_event_interruptible(evdev->wait,
+                               client->packet_head != client->tail ||
+                               !evdev->exist);
+               if (retval)
+                       return retval;
+       }
 
        if (!evdev->exist)
                return -ENODEV;