Skip to content

Commit 0543e4e

Browse files
tatokisgregkh
authored andcommitted
usb: core: Don't hold the device lock while sleeping in do_proc_control()
Since commit ae8709b ("USB: core: Make do_proc_control() and do_proc_bulk() killable") if a device has the USB_QUIRK_DELAY_CTRL_MSG quirk set, it will temporarily block all other URBs (e.g. interrupts) while sleeping due to a control. This results in noticeable delays when, for example, a userspace usbfs application is sending URB interrupts at a high rate to a keyboard and simultaneously updates the lock indicators using controls. Interrupts with direction set to IN are also affected by this, meaning that delivery of HID reports (containing scancodes) to the usbfs application is delayed as well. This patch fixes the regression by calling msleep() while the device mutex is unlocked, as was the case originally with usb_control_msg(). Fixes: ae8709b ("USB: core: Make do_proc_control() and do_proc_bulk() killable") Cc: stable <[email protected]> Acked-by: Alan Stern <[email protected]> Signed-off-by: Tasos Sahanidis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ab7aa28 commit 0543e4e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/usb/core/devio.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,12 +1209,16 @@ static int do_proc_control(struct usb_dev_state *ps,
12091209

12101210
usb_unlock_device(dev);
12111211
i = usbfs_start_wait_urb(urb, tmo, &actlen);
1212+
1213+
/* Linger a bit, prior to the next control message. */
1214+
if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
1215+
msleep(200);
12121216
usb_lock_device(dev);
12131217
snoop_urb(dev, NULL, pipe, actlen, i, COMPLETE, tbuf, actlen);
12141218
if (!i && actlen) {
12151219
if (copy_to_user(ctrl->data, tbuf, actlen)) {
12161220
ret = -EFAULT;
1217-
goto recv_fault;
1221+
goto done;
12181222
}
12191223
}
12201224
} else {
@@ -1231,6 +1235,10 @@ static int do_proc_control(struct usb_dev_state *ps,
12311235

12321236
usb_unlock_device(dev);
12331237
i = usbfs_start_wait_urb(urb, tmo, &actlen);
1238+
1239+
/* Linger a bit, prior to the next control message. */
1240+
if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
1241+
msleep(200);
12341242
usb_lock_device(dev);
12351243
snoop_urb(dev, NULL, pipe, actlen, i, COMPLETE, NULL, 0);
12361244
}
@@ -1242,10 +1250,6 @@ static int do_proc_control(struct usb_dev_state *ps,
12421250
}
12431251
ret = (i < 0 ? i : actlen);
12441252

1245-
recv_fault:
1246-
/* Linger a bit, prior to the next control message. */
1247-
if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
1248-
msleep(200);
12491253
done:
12501254
kfree(dr);
12511255
usb_free_urb(urb);

0 commit comments

Comments
 (0)