HID: hidraw: fix nonblock read return EAGAIN after device removed
authorFounder Fang <founder.fang@gmail.com>
Wed, 21 Nov 2012 07:20:31 +0000 (15:20 +0800)
committerJiri Kosina <jkosina@suse.cz>
Mon, 26 Nov 2012 13:18:15 +0000 (14:18 +0100)
When nonblock read the condition check (file->f_flags & O_NONBLOCK) always be
true, signal_pending and device exist checking never get a chance to run, so
the user mode code always get EAGAIN even if device removed. move nonblock mode
checking to the last can fix this problem.

Signed-off-by: Founder Fang <founder.fang@gmail.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hidraw.c

index 7c47fc3f7b2b0b28f27021c75bb3b8d8f3771c4d..1d8c0219117ead17eaa73aa0bfda845ed52b7951 100644 (file)
@@ -57,10 +57,6 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
                        set_current_state(TASK_INTERRUPTIBLE);
 
                        while (list->head == list->tail) {
-                               if (file->f_flags & O_NONBLOCK) {
-                                       ret = -EAGAIN;
-                                       break;
-                               }
                                if (signal_pending(current)) {
                                        ret = -ERESTARTSYS;
                                        break;
@@ -69,6 +65,10 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count,
                                        ret = -EIO;
                                        break;
                                }
+                               if (file->f_flags & O_NONBLOCK) {
+                                       ret = -EAGAIN;
+                                       break;
+                               }
 
                                /* allow O_NONBLOCK to work well from other threads */
                                mutex_unlock(&list->read_mutex);