[Fwd: [PATCH] Avoid scary error message on input device unplug]

Bernardo Innocenti bernie at codewiz.org
Wed Nov 14 13:04:54 PST 2007


(I posted it to the wrong address)

-------- Original Message --------
Subject: [PATCH] Avoid scary error message on input device unplug
Date: Wed, 14 Nov 2007 15:49:36 -0500
From: Bernardo Innocenti <bernie at codewiz.org>
Organization: One Laptop Per Child
To: Zephaniah E. Hull <warp at aehallh.com>
CC: xorg at freedesktop.org, Alexander.M.Latham at dartmouth.edu, Bernardo Innocenti <bernie at codewiz.org>

Reading from evdev can fail when you hot-unplog a USB mouse.  In this case,
read() returns -1 and errno is set to ENODEV.

This patch moves the test for this event before the test for the
abnormal error where read() returned something that doesn't match
the size of an event.

Signed-off-by: Bernardo Innocenti <bernie at codewiz.org>
---
 src/evdev.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index dc801d0..20666a4 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -224,15 +224,15 @@ EvdevReadInput(InputInfoPtr pInfo)
     while (xf86WaitForInput (pInfo->fd, 0) > 0) {
         len = read(pInfo->fd, &ev, sizeof(ev));
         if (len != sizeof(ev)) {
-            /* The kernel promises that we always only read a complete
-             * event, so len != sizeof ev is an error. */
-            xf86Msg(X_ERROR, "Read error: %s (%d, %d != %zd)\n",
-		    strerror(errno), errno, len, sizeof (ev));
 	    if (len < 0)
             {
                 xf86DisableDevice(pInfo->dev, TRUE);
                 return;
             }
+            /* The kernel promises that we always only read a complete
+             * event, so len != sizeof ev is an error. */
+            xf86Msg(X_ERROR, "Read error: %s (%d, %d != %zd)\n",
+		    strerror(errno), errno, len, sizeof (ev));
             break;
         }
 
-- 
1.5.3.5.561.g140d


-- 
 \___/
 |___|   Bernardo Innocenti - http://www.codewiz.org/
  \___\  One Laptop Per Child - http://www.laptop.org/



More information about the xorg mailing list