summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-11-28 00:10:44 +0100
committerJiri Kosina <jkosina@suse.cz>2012-11-28 00:10:44 +0100
commit13f19624029f43f5d0f98a96a9e6ba4d38da96a9 (patch)
treeddd3db2a9e7f5d5e811c5343ae1b922a77d6eecb
parent4cc8541782140e9ccbece5c8ac367fbf659b16d9 (diff)
downloadlwn-13f19624029f43f5d0f98a96a9e6ba4d38da96a9.tar.gz
lwn-13f19624029f43f5d0f98a96a9e6ba4d38da96a9.zip
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 711c9656ec0f..87bd64959a91 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
prepare_to_wait(&list->hiddev->wait, &wait, TASK_INTERRUPTIBLE);
while (list->head == list->tail) {
- if (file->f_flags & O_NONBLOCK) {
- retval = -EAGAIN;
- break;
- }
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
@@ -373,6 +369,10 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
retval = -EIO;
break;
}
+ if (file->f_flags & O_NONBLOCK) {
+ retval = -EAGAIN;
+ break;
+ }
/* let O_NONBLOCK tasks run */
mutex_unlock(&list->thread_lock);