Subject: bin/15019: usbhidctl -l generates ugly error on device detach
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dave@dtsp.co.nz>
List: netbsd-bugs
Date: 12/21/2001 08:29:22
>Number: 15019
>Category: bin
>Synopsis: usbhidctl -l generates ugly error on device detach
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 21 00:18:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: David Sainty
>Release: NetBSD 1.5X
>Organization:
Dynamic Technology Services and Products Ltd (NZ)
>Environment:
System: NetBSD tequila.dave.dtsp.co.nz 1.5X NetBSD 1.5X (TEQUILA) #0: Sat Dec 1 17:24:03 NZDT 2001 dave@tequila.dave.dtsp.co.nz:/vol/tequila/userD/NetBSD-tequila/src/sys/arch/i386/compile/TEQUILA i386
Architecture: i386
Machine: i386
>Description:
When using the loop option to usbhidctl and the device is detached,
usbhidctl generates a rather ugly error, like:
usbhidctl: bad read -1 != 4: Input/Output error
Given that it is easy to generate an error like this, the code should
generate a cleaner error. The code is currently a little careless, on
the assumption that unexpected results would typically never happen.
>How-To-Repeat:
Pull the plug on a USB HID device whilst looping with usbhidctl -l
>Fix:
--- src/usr.bin/usbhidctl/usbhid.c.orig Tue Oct 23 19:27:20 2001
+++ src/usr.bin/usbhidctl/usbhid.c Fri Dec 21 21:14:02 2001
@@ -570,9 +570,11 @@
ssize_t readlen;
readlen = read(hidfd, dbuf, dlen);
- if (readlen < 0 || dlen != (size_t)readlen)
- err(1, "bad read %ld != %ld",
- (long)readlen, (long)dlen);
+ if (readlen < 0)
+ err(1, "Device read error");
+ if (dlen != (size_t)readlen)
+ errx(1, "Unexpected response length: %lu != %lu",
+ (unsigned long)readlen, (unsigned long)dlen);
collind = 0;
hdata = hid_start_parse(rd, 1 << hid_input);
>Release-Note:
>Audit-Trail:
>Unformatted: