From: Laurent Gauthier Date: Tue, 8 Sep 2020 22:11:49 +0000 (+0200) Subject: HID: hid-debug: fix nonblocking read semantics wrt EIO/ERESTARTSYS X-Git-Tag: v5.10.7~1409^2~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c27e08820bc6cb7d483a8d87589bdbbbf10f2306;p=platform%2Fkernel%2Flinux-rpi.git 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 and Jiri Kosina . Signed-off-by: Laurent Gauthier Signed-off-by: Jiri Kosina --- diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index 9453147..d7eaf91 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -1101,11 +1101,6 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, set_current_state(TASK_INTERRUPTIBLE); while (kfifo_is_empty(&list->hid_debug_fifo)) { - if (file->f_flags & O_NONBLOCK) { - ret = -EAGAIN; - break; - } - if (signal_pending(current)) { ret = -ERESTARTSYS; break; @@ -1122,6 +1117,11 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, goto out; } + if (file->f_flags & O_NONBLOCK) { + ret = -EAGAIN; + break; + } + /* allow O_NONBLOCK from other threads */ mutex_unlock(&list->read_mutex); schedule();