Skip to content

Commit c27e088

Browse files
laurentgauthierJiri Kosina
authored andcommitted
HID: hid-debug: 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. Based on similar to patches hidraw and hiddev by Founder Fang <founder.fang@gmail.com> and Jiri Kosina <jkosina@suse.cz>. Signed-off-by: Laurent Gauthier <laurent.gauthier@soccasys.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent fc3abb5 commit c27e088

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎drivers/hid/hid-debug.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,6 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
11011101
set_current_state(TASK_INTERRUPTIBLE);
11021102

11031103
while (kfifo_is_empty(&list->hid_debug_fifo)) {
1104-
if (file->f_flags & O_NONBLOCK) {
1105-
ret = -EAGAIN;
1106-
break;
1107-
}
1108-
11091104
if (signal_pending(current)) {
11101105
ret = -ERESTARTSYS;
11111106
break;
@@ -1122,6 +1117,11 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
11221117
goto out;
11231118
}
11241119

1120+
if (file->f_flags & O_NONBLOCK) {
1121+
ret = -EAGAIN;
1122+
break;
1123+
}
1124+
11251125
/* allow O_NONBLOCK from other threads */
11261126
mutex_unlock(&list->read_mutex);
11271127
schedule();

0 commit comments

Comments
 (0)