Skip to content

Commit d2f311e

Browse files
AlanSternJiri Kosina
authored andcommitted
HID: usbhid: Simplify code in hid_submit_ctrl()
This patch makes a small simplification to the code in hid_submit_ctrl(). The test for maxpacket being > 0 is unnecessary, because endpoint 0 always has a maxpacket value which is >= 8. Furthermore, endpoint 0's maxpacket value is always a power of 2, so instead of open-coding the round-to-next-multiple computation we can call the optimized round_up() routine. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 0a824ef commit d2f311e

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

drivers/hid/usbhid/hid-core.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,10 @@ static int hid_submit_ctrl(struct hid_device *hid)
388388
usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
389389
maxpacket = usb_maxpacket(hid_to_usb_dev(hid),
390390
usbhid->urbctrl->pipe, 0);
391-
if (maxpacket > 0) {
392-
len += (len == 0); /* Don't allow 0-length reports */
393-
len = DIV_ROUND_UP(len, maxpacket);
394-
len *= maxpacket;
395-
if (len > usbhid->bufsize)
396-
len = usbhid->bufsize;
397-
} else
398-
len = 0;
391+
len += (len == 0); /* Don't allow 0-length reports */
392+
len = round_up(len, maxpacket);
393+
if (len > usbhid->bufsize)
394+
len = usbhid->bufsize;
399395
}
400396
usbhid->urbctrl->transfer_buffer_length = len;
401397
usbhid->urbctrl->dev = hid_to_usb_dev(hid);

0 commit comments

Comments
 (0)