Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Laurent Gauthier and committed by
Jiri Kosina
c27e0882 fc3abb53

+5 -5
+5 -5
drivers/hid/hid-debug.c
··· 1101 1101 set_current_state(TASK_INTERRUPTIBLE); 1102 1102 1103 1103 while (kfifo_is_empty(&list->hid_debug_fifo)) { 1104 - if (file->f_flags & O_NONBLOCK) { 1105 - ret = -EAGAIN; 1106 - break; 1107 - } 1108 - 1109 1104 if (signal_pending(current)) { 1110 1105 ret = -ERESTARTSYS; 1111 1106 break; ··· 1115 1120 ret = -EIO; 1116 1121 set_current_state(TASK_RUNNING); 1117 1122 goto out; 1123 + } 1124 + 1125 + if (file->f_flags & O_NONBLOCK) { 1126 + ret = -EAGAIN; 1127 + break; 1118 1128 } 1119 1129 1120 1130 /* allow O_NONBLOCK from other threads */