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>
This commit is contained in:
parent
4cc8541782
commit
13f1962402
1 changed files with 4 additions and 4 deletions
|
@ -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);
|
prepare_to_wait(&list->hiddev->wait, &wait, TASK_INTERRUPTIBLE);
|
||||||
|
|
||||||
while (list->head == list->tail) {
|
while (list->head == list->tail) {
|
||||||
if (file->f_flags & O_NONBLOCK) {
|
|
||||||
retval = -EAGAIN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
||||||
retval = -ERESTARTSYS;
|
retval = -ERESTARTSYS;
|
||||||
break;
|
break;
|
||||||
|
@ -373,6 +369,10 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
|
||||||
retval = -EIO;
|
retval = -EIO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (file->f_flags & O_NONBLOCK) {
|
||||||
|
retval = -EAGAIN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* let O_NONBLOCK tasks run */
|
/* let O_NONBLOCK tasks run */
|
||||||
mutex_unlock(&list->thread_lock);
|
mutex_unlock(&list->thread_lock);
|
||||||
|
|
Loading…
Reference in a new issue