aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-11-27 18:10:44 -0500
committerJiri Kosina <jkosina@suse.cz>2012-11-27 18:10:44 -0500
commit13f19624029f43f5d0f98a96a9e6ba4d38da96a9 (patch)
treeddd3db2a9e7f5d5e811c5343ae1b922a77d6eecb
parent4cc8541782140e9ccbece5c8ac367fbf659b16d9 (diff)
HID: hiddev: fix nonblocking read semantics wrt EIO/ERESTARTSYS
When the file has been open in non-blocking mode, EIO or ERESTARTSYS would never be returned even if they should (for example when device has been unplugged, you want EIO and not EAGAIN to be returned). Move the O_NONBLOCK check after other checks have been performed. Base on similar patch done to hidraw by Founder Fang <founder.fang@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/usbhid/hiddev.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 711c9656ec0..87bd64959a9 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -361,10 +361,6 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
361 prepare_to_wait(&list->hiddev->wait, &wait, TASK_INTERRUPTIBLE); 361 prepare_to_wait(&list->hiddev->wait, &wait, TASK_INTERRUPTIBLE);
362 362
363 while (list->head == list->tail) { 363 while (list->head == list->tail) {
364 if (file->f_flags & O_NONBLOCK) {
365 retval = -EAGAIN;
366 break;
367 }
368 if (signal_pending(current)) { 364 if (signal_pending(current)) {
369 retval = -ERESTARTSYS; 365 retval = -ERESTARTSYS;
370 break; 366 break;
@@ -373,6 +369,10 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
373 retval = -EIO; 369 retval = -EIO;
374 break; 370 break;
375 } 371 }
372 if (file->f_flags & O_NONBLOCK) {
373 retval = -EAGAIN;
374 break;
375 }
376 376
377 /* let O_NONBLOCK tasks run */ 377 /* let O_NONBLOCK tasks run */
378 mutex_unlock(&list->thread_lock); 378 mutex_unlock(&list->thread_lock);