Skip to content

Commit 5b0545d

Browse files
author
Jiri Kosina
committed
Revert "HID: usbhid: do not sleep when opening device"
This reverts commit d313279. This patch causes a regression with quite a few devices, as probing fails because of the race where the first IRQ is dropped on the floor (after hid_device_io_start() happens, but before the 50ms timeout passess), and report descriptor never gets parsed and populated. As this is just a boot time micro-optimization, let's revert the patch for 5.9 now, and fix this properly eventually for next merge window. Link: https://bugzilla.kernel.org/show_bug.cgi?id=208935 Reported-by: Johannes Hirte <johannes.hirte@datenkhaos.de> Reported-by: Marius Zachmann <mail@mariuszachmann.de> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 25a097f commit 5b0545d

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

drivers/hid/usbhid/hid-core.c

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <linux/wait.h>
2727
#include <linux/workqueue.h>
2828
#include <linux/string.h>
29-
#include <linux/timekeeping.h>
3029

3130
#include <linux/usb.h>
3231

@@ -96,18 +95,6 @@ static int hid_start_in(struct hid_device *hid)
9695
set_bit(HID_NO_BANDWIDTH, &usbhid->iofl);
9796
} else {
9897
clear_bit(HID_NO_BANDWIDTH, &usbhid->iofl);
99-
100-
if (test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) {
101-
/*
102-
* In case events are generated while nobody was
103-
* listening, some are released when the device
104-
* is re-opened. Wait 50 msec for the queue to
105-
* empty before allowing events to go through
106-
* hid.
107-
*/
108-
usbhid->input_start_time =
109-
ktime_add_ms(ktime_get_coarse(), 50);
110-
}
11198
}
11299
}
113100
spin_unlock_irqrestore(&usbhid->lock, flags);
@@ -293,23 +280,20 @@ static void hid_irq_in(struct urb *urb)
293280
if (!test_bit(HID_OPENED, &usbhid->iofl))
294281
break;
295282
usbhid_mark_busy(usbhid);
296-
if (test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) {
297-
if (ktime_before(ktime_get_coarse(),
298-
usbhid->input_start_time))
299-
break;
300-
clear_bit(HID_RESUME_RUNNING, &usbhid->iofl);
283+
if (!test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) {
284+
hid_input_report(urb->context, HID_INPUT_REPORT,
285+
urb->transfer_buffer,
286+
urb->actual_length, 1);
287+
/*
288+
* autosuspend refused while keys are pressed
289+
* because most keyboards don't wake up when
290+
* a key is released
291+
*/
292+
if (hid_check_keys_pressed(hid))
293+
set_bit(HID_KEYS_PRESSED, &usbhid->iofl);
294+
else
295+
clear_bit(HID_KEYS_PRESSED, &usbhid->iofl);
301296
}
302-
hid_input_report(urb->context, HID_INPUT_REPORT,
303-
urb->transfer_buffer, urb->actual_length, 1);
304-
/*
305-
* autosuspend refused while keys are pressed
306-
* because most keyboards don't wake up when
307-
* a key is released
308-
*/
309-
if (hid_check_keys_pressed(hid))
310-
set_bit(HID_KEYS_PRESSED, &usbhid->iofl);
311-
else
312-
clear_bit(HID_KEYS_PRESSED, &usbhid->iofl);
313297
break;
314298
case -EPIPE: /* stall */
315299
usbhid_mark_busy(usbhid);
@@ -736,6 +720,17 @@ static int usbhid_open(struct hid_device *hid)
736720

737721
usb_autopm_put_interface(usbhid->intf);
738722

723+
/*
724+
* In case events are generated while nobody was listening,
725+
* some are released when the device is re-opened.
726+
* Wait 50 msec for the queue to empty before allowing events
727+
* to go through hid.
728+
*/
729+
if (res == 0)
730+
msleep(50);
731+
732+
clear_bit(HID_RESUME_RUNNING, &usbhid->iofl);
733+
739734
Done:
740735
mutex_unlock(&usbhid->mutex);
741736
return res;

drivers/hid/usbhid/usbhid.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include <linux/types.h>
1515
#include <linux/slab.h>
16-
#include <linux/ktime.h>
1716
#include <linux/list.h>
1817
#include <linux/mutex.h>
1918
#include <linux/timer.h>
@@ -84,7 +83,6 @@ struct usbhid_device {
8483
struct mutex mutex; /* start/stop/open/close */
8584
spinlock_t lock; /* fifo spinlock */
8685
unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
87-
ktime_t input_start_time; /* When to start handling input */
8886
struct timer_list io_retry; /* Retry timer */
8987
unsigned long stop_retry; /* Time to give up, in jiffies */
9088
unsigned int retry_delay; /* Delay length in ms */

0 commit comments

Comments
 (0)