linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: hid-debug: fix nonblocking read semantics wrt EIO/ERESTARTSYS
@ 2020-09-08 22:11 Laurent Gauthier
  2020-09-09  6:48 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Gauthier @ 2020-09-08 22:11 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel
  Cc: laurent.gauthier

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>
---
 drivers/hid/hid-debug.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 9453147d020d..d7eaf9100370 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();
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] HID: hid-debug: fix nonblocking read semantics wrt EIO/ERESTARTSYS
  2020-09-08 22:11 [PATCH] HID: hid-debug: fix nonblocking read semantics wrt EIO/ERESTARTSYS Laurent Gauthier
@ 2020-09-09  6:48 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2020-09-09  6:48 UTC (permalink / raw)
  To: Laurent Gauthier; +Cc: Benjamin Tissoires, linux-input, linux-kernel

On Wed, 9 Sep 2020, Laurent Gauthier wrote:

> 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.

Makes sense, good catch. Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-09  6:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 22:11 [PATCH] HID: hid-debug: fix nonblocking read semantics wrt EIO/ERESTARTSYS Laurent Gauthier
2020-09-09  6:48 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).