kernel-fxtec-pro1x/drivers/usb/input
Christian Krause 13b58ee518 [PATCH] USB: fix bug in handling of highspeed usb HID devices
During the development of an USB device I found a bug in the handling of
Highspeed HID devices in the kernel.

What happened?

Highspeed HID devices are correctly recognized and enumerated by the
kernel. But even if usbhid kernel module is loaded, no HID reports are
received by the kernel.

The output of the hardware USB analyzer told me that the host doesn't
even poll for interrupt IN transfers (even the "interrupt in" USB
transfer are polled by the host).

After some debugging in hid-core.c I've found the reason.

In case of a highspeed device, the endpoint interval is re-calculated in
driver/usb/input/hid-core.c:

line 1669:
             /* handle potential highspeed HID correctly */
             interval = endpoint->bInterval;
             if (dev->speed == USB_SPEED_HIGH)
                   interval = 1 << (interval - 1);

Basically this calculation is correct (refer to USB 2.0 spec, 9.6.6).
This new calculated value of "interval" is used as input for
usb_fill_int_urb:

line 1685:

            usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, 0,
                   hid_irq_in, hid, interval);

Unfortunately the same calculation as above is done a second time in
usb_fill_int_urb in the file include/linux/usb.h:

line 933:
        if (dev->speed == USB_SPEED_HIGH)
                urb->interval = 1 << (interval - 1);
        else
                urb->interval = interval;

This means, that if the endpoint descriptor (of a high speed device)
specifies e.g. bInterval = 7, the urb->interval gets the value:

hid-core.c: interval = 1 << (7-1) = 0x40 = 64
urb->interval = 1 << (interval -1) = 1 << (63) = integer overflow

Because of this the value of urb->interval is sometimes negative and is
rejected in core/urb.c:
line 353:
                /* too small? */
                if (urb->interval <= 0)
                        return -EINVAL;

The conclusion is, that the recalculaton of the interval (which is
necessary for highspeed) should not be made twice, because this is
simply wrong. ;-)

Re-calculation in usb_fill_int_urb makes more sense, because it is the
most general approach. So it would make sense to remove it from
hid-core.c.

Because in hid-core.c the interval variable is only used for calling
usb_fill_int_urb, it is no problem to remove the highspeed
re-calculation in this file.

Signed-off-by: Christian Krause <chkr@plauener.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-17 14:45:49 -07:00
..
acecad.c [PATCH] USB: convert kcalloc to kzalloc 2005-09-07 16:57:46 -07:00
aiptek.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
appletouch.c [PATCH] USB: add apple usb touchpad driver 2005-09-12 12:23:39 -07:00
ati_remote.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
fixp-arith.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
hid-core.c [PATCH] USB: fix bug in handling of highspeed usb HID devices 2005-10-17 14:45:49 -07:00
hid-debug.h Input: HID - add more consumer usages 2005-09-05 00:08:08 -05:00
hid-ff.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
hid-input.c Input: HID - add mapping for Powerbook USB keyboard 2005-09-05 01:57:33 -05:00
hid-lgff.c Input: whitespace fixes in drivers/usb/input 2005-05-29 02:29:01 -05:00
hid-tmff.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
hid.h Input: HID - add mapping for Powerbook USB keyboard 2005-09-05 01:57:33 -05:00
hiddev.c Input: HIDDEV - make HIDIOCSREPORT wait IO completion 2005-09-05 01:57:46 -05:00
itmtouch.c [PATCH] USB: convert kcalloc to kzalloc 2005-09-07 16:57:46 -07:00
kbtab.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
Kconfig [PATCH] USB: add apple usb touchpad driver 2005-09-12 12:23:39 -07:00
keyspan_remote.c [PATCH] USB: fix keyspan_remote endian bug on probe 2005-09-08 16:22:17 -07:00
Makefile [PATCH] USB: add apple usb touchpad driver 2005-09-12 12:23:39 -07:00
map_to_7segment.h [PATCH] input-driver-yealink-P1K-usb-phone 2005-09-08 16:40:57 -07:00
mtouchusb.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
pid.c [PATCH] USB: convert kcalloc to kzalloc 2005-09-07 16:57:46 -07:00
pid.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
powermate.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
touchkitusb.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
usbkbd.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
usbmouse.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
wacom.c [PATCH] USB: fix usb wacom tablet driver bug 2005-08-16 21:06:25 -07:00
xpad.c Input: introduce usb_to_input_id() to uniformly produce 2005-06-30 00:49:08 -05:00
yealink.c [PATCH] USB: yealink: fix htons usage, documentation updates 2005-09-08 16:40:57 -07:00
yealink.h [PATCH] input-driver-yealink-P1K-usb-phone 2005-09-08 16:40:57 -07:00