ChangeSet 1.1511, 2004/01/20 16:02:17-08:00, akropel1@rochester.rr.com [PATCH] USB: hiddev HIDIOCGREPORT not blocking in 2.6 I've noticed in 2.6 kernels that HIDIOCGREPORT does not wait for io completion before returning to the caller. This creates a few unpleasant issues for userspace: First, code sequences such as... ioctl(fd, HIDIOCGREPORT, &rinfo); ioctl(fd, HIDIOCGUSAGE, &uinfo); ioctl(fd, HIDIOCGSTRING, &sdesc); ...that used to work in 2.4 now fail in 2.6 if the device takes more than a few milliseconds to respond to HIDIOCGREPORT. (I'm seeing this issue on APC UPSes, FWIW.) Second, userspace code can easily flood the kernel with control messages since the kernel provides no "backpressure". The result is a lot of "hid-core.c: control queue full" errors and lost reports. 2.6 hid-core.c appears to submit the request and return immediately. Although the 2.4 code differs significantly, I traced the call path to usb-core.c, which seems to block with a timeout, so the code supports my userspace observation. (Assuming I didn't misread it.) drivers/usb/input/hid.h | 1 + drivers/usb/input/hiddev.c | 1 + 2 files changed, 2 insertions(+) diff -Nru a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h --- a/drivers/usb/input/hid.h Tue Jan 20 17:33:34 2004 +++ b/drivers/usb/input/hid.h Tue Jan 20 17:33:34 2004 @@ -449,6 +449,7 @@ void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir); void hid_init_reports(struct hid_device *hid); int hid_find_report_by_usage(struct hid_device *hid, __u32 wanted_usage, struct hid_report **report, int type); +int hid_wait_io(struct hid_device* hid); #ifdef CONFIG_HID_FF diff -Nru a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c --- a/drivers/usb/input/hiddev.c Tue Jan 20 17:33:34 2004 +++ b/drivers/usb/input/hiddev.c Tue Jan 20 17:33:34 2004 @@ -509,6 +509,7 @@ return -EINVAL; hid_submit_report(hid, report, USB_DIR_IN); + hid_wait_io(hid); return 0;