linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed
@ 2012-11-21  7:20 founder.fang
  2012-11-26  2:30 ` founder.fang
  0 siblings, 1 reply; 4+ messages in thread
From: founder.fang @ 2012-11-21  7:20 UTC (permalink / raw)
  To: jkosina; +Cc: linux-input, linux-kernel

when nonblock read the condition check (file->f_flags & O_NONBLOCK)
always be true,
signal_pending and device exist checking never get a chance to run, so
the user mode code always
get EAGAIN even if device removed. move nonblock mode checking to the
last can fix this problem.

Signed-off-by: Founder Fang <founder.fang@gmail.com>

--- hid-git/drivers/hid/hidraw.c.orig	2012-11-21 14:37:04.977106383 +0800
+++ hid-git/drivers/hid/hidraw.c	2012-11-21 14:40:35.882152200 +0800
@@ -57,10 +57,6 @@ static ssize_t hidraw_read(struct file *
 			set_current_state(TASK_INTERRUPTIBLE);

 			while (list->head == list->tail) {
-				if (file->f_flags & O_NONBLOCK) {
-					ret = -EAGAIN;
-					break;
-				}
 				if (signal_pending(current)) {
 					ret = -ERESTARTSYS;
 					break;
@@ -69,6 +65,10 @@ static ssize_t hidraw_read(struct file *
 					ret = -EIO;
 					break;
 				}
+				if (file->f_flags & O_NONBLOCK) {
+					ret = -EAGAIN;
+					break;
+				}

 				/* allow O_NONBLOCK to work well from other threads */
 				mutex_unlock(&list->read_mutex);

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

* [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed
  2012-11-21  7:20 [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed founder.fang
@ 2012-11-26  2:30 ` founder.fang
  2012-11-26  8:15   ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: founder.fang @ 2012-11-26  2:30 UTC (permalink / raw)
  To: dmitry.torokhov, jkosina, linux-input; +Cc: linux-kernel

Hi Linux-Input, Jiri, Dmitry,
this patch is related to nonblock read on hidraw device.
when nonblock read the condition check (file->f_flags & O_NONBLOCK)
always be true,
signal_pending and device exist checking never get a chance to run, so
the user mode code always
get EAGAIN even if device removed. move nonblock mode checking to the
last can fix this problem.

Signed-off-by: Founder Fang <founder.fang@gmail.com>

--- hid-git/drivers/hid/hidraw.c.orig   2012-11-21 14:37:04.977106383 +0800
+++ hid-git/drivers/hid/hidraw.c        2012-11-21 14:40:35.882152200 +0800
@@ -57,10 +57,6 @@ static ssize_t hidraw_read(struct file *
                        set_current_state(TASK_INTERRUPTIBLE);

                        while (list->head == list->tail) {
-                               if (file->f_flags & O_NONBLOCK) {
-                                       ret = -EAGAIN;
-                                       break;
-                               }
                                if (signal_pending(current)) {
                                        ret = -ERESTARTSYS;
                                        break;
@@ -69,6 +65,10 @@ static ssize_t hidraw_read(struct file *
                                        ret = -EIO;
                                        break;
                                }
+                               if (file->f_flags & O_NONBLOCK) {
+                                       ret = -EAGAIN;
+                                       break;
+                               }

                                /* allow O_NONBLOCK to work well from
other threads */
                                mutex_unlock(&list->read_mutex);

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

* Re: [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed
  2012-11-26  2:30 ` founder.fang
@ 2012-11-26  8:15   ` Dmitry Torokhov
  2012-11-26 13:18     ` Jiri Kosina
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2012-11-26  8:15 UTC (permalink / raw)
  To: founder.fang; +Cc: jkosina, linux-input, linux-kernel

Hi Founder,

On Mon, Nov 26, 2012 at 10:30:37AM +0800, founder.fang wrote:
> Hi Linux-Input, Jiri, Dmitry,
> this patch is related to nonblock read on hidraw device.
> when nonblock read the condition check (file->f_flags & O_NONBLOCK)
> always be true,
> signal_pending and device exist checking never get a chance to run, so
> the user mode code always
> get EAGAIN even if device removed. move nonblock mode checking to the
> last can fix this problem.
> 
> Signed-off-by: Founder Fang <founder.fang@gmail.com>
> 

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Makes sense to me. However it looks like your mailer line-wrapped the
patch, please resend so Jiri can apply it.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed
  2012-11-26  8:15   ` Dmitry Torokhov
@ 2012-11-26 13:18     ` Jiri Kosina
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2012-11-26 13:18 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: founder.fang, linux-input, linux-kernel

On Mon, 26 Nov 2012, Dmitry Torokhov wrote:

> > Hi Linux-Input, Jiri, Dmitry,
> > this patch is related to nonblock read on hidraw device.
> > when nonblock read the condition check (file->f_flags & O_NONBLOCK)
> > always be true,
> > signal_pending and device exist checking never get a chance to run, so
> > the user mode code always
> > get EAGAIN even if device removed. move nonblock mode checking to the
> > last can fix this problem.
> > 
> > Signed-off-by: Founder Fang <founder.fang@gmail.com>
> > 
> 
> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Makes sense to me. However it looks like your mailer line-wrapped the
> patch, please resend so Jiri can apply it.

For some reason, the patch has been sent to me twice, once it has been 
fine and the second time it has been line wrapped.

I have now applied the non-broken version. Thanks,

-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2012-11-26 13:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-21  7:20 [PATCH] HID: hidraw: fix nonblock read return EAGAIN after device removed founder.fang
2012-11-26  2:30 ` founder.fang
2012-11-26  8:15   ` Dmitry Torokhov
2012-11-26 13:18     ` 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).