input: evdev: do not block waiting for an event if fd is nonblock
authorDima Zavin <dima@android.com>
Wed, 5 Oct 2011 00:10:45 +0000 (17:10 -0700)
committerDima Zavin <dima@android.com>
Wed, 5 Oct 2011 05:51:05 +0000 (22:51 -0700)
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.

Change-Id: Icd0f59f8cc98392be4c4d13bd45b5cf94317eb5a
Signed-off-by: Dima Zavin <dima@android.com>
drivers/input/evdev.c

index 10ae1c966a3512919148cbdbafbcf3c45e2e1e79..5c5f9db280755cfe7cc4742a1d5fbb9ddc5d511e 100644 (file)
@@ -405,14 +405,12 @@ 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;