Skip to content

Commit 5049307

Browse files
mkubecekJiri Kosina
authored andcommitted
HID: usbhid: Fix flood of "control queue full" messages
[patch description by Alan Stern] Commit 7652dd2 ("USB: core: Check buffer length matches wLength for control transfers") causes control URB submissions to fail if the transfer_buffer_length value disagrees with the setup packet's wLength valuel. Unfortunately, it turns out that the usbhid can trigger this failure mode when it submits a control request for an input report: It pads the transfer buffer size to a multiple of the maxpacket value but does not increase wLength correspondingly. These failures have caused problems for people using an APS UPC, in the form of a flood of log messages resembling: hid-generic 0003:051D:0002.0002: control queue full This patch fixes the problem by setting the wLength value equal to the padded transfer_buffer_length value in hid_submit_ctrl(). As a nice bonus, the code which stores the transfer_buffer_length value is now shared between the two branches of an "if" statement, so it can be de-duplicated. Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Fixes: 7652dd2 ("USB: core: Check buffer length matches wLength for control transfers") Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name> Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent f7744fa commit 5049307

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

drivers/hid/usbhid/hid-core.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,27 +377,26 @@ static int hid_submit_ctrl(struct hid_device *hid)
377377
len = hid_report_len(report);
378378
if (dir == USB_DIR_OUT) {
379379
usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
380-
usbhid->urbctrl->transfer_buffer_length = len;
381380
if (raw_report) {
382381
memcpy(usbhid->ctrlbuf, raw_report, len);
383382
kfree(raw_report);
384383
usbhid->ctrl[usbhid->ctrltail].raw_report = NULL;
385384
}
386385
} else {
387-
int maxpacket, padlen;
386+
int maxpacket;
388387

389388
usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
390389
maxpacket = usb_maxpacket(hid_to_usb_dev(hid),
391390
usbhid->urbctrl->pipe, 0);
392391
if (maxpacket > 0) {
393-
padlen = DIV_ROUND_UP(len, maxpacket);
394-
padlen *= maxpacket;
395-
if (padlen > usbhid->bufsize)
396-
padlen = usbhid->bufsize;
392+
len = DIV_ROUND_UP(len, maxpacket);
393+
len *= maxpacket;
394+
if (len > usbhid->bufsize)
395+
len = usbhid->bufsize;
397396
} else
398-
padlen = 0;
399-
usbhid->urbctrl->transfer_buffer_length = padlen;
397+
len = 0;
400398
}
399+
usbhid->urbctrl->transfer_buffer_length = len;
401400
usbhid->urbctrl->dev = hid_to_usb_dev(hid);
402401

403402
usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;

0 commit comments

Comments
 (0)