|
26 | 26 | #include <linux/wait.h>
|
27 | 27 | #include <linux/workqueue.h>
|
28 | 28 | #include <linux/string.h>
|
| 29 | +#include <linux/timekeeping.h> |
29 | 30 |
|
30 | 31 | #include <linux/usb.h>
|
31 | 32 |
|
@@ -95,6 +96,18 @@ static int hid_start_in(struct hid_device *hid)
|
95 | 96 | set_bit(HID_NO_BANDWIDTH, &usbhid->iofl);
|
96 | 97 | } else {
|
97 | 98 | 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 | + } |
98 | 111 | }
|
99 | 112 | }
|
100 | 113 | spin_unlock_irqrestore(&usbhid->lock, flags);
|
@@ -280,20 +293,23 @@ static void hid_irq_in(struct urb *urb)
|
280 | 293 | if (!test_bit(HID_OPENED, &usbhid->iofl))
|
281 | 294 | break;
|
282 | 295 | usbhid_mark_busy(usbhid);
|
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); |
| 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); |
296 | 301 | }
|
| 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); |
297 | 313 | break;
|
298 | 314 | case -EPIPE: /* stall */
|
299 | 315 | usbhid_mark_busy(usbhid);
|
@@ -720,17 +736,6 @@ static int usbhid_open(struct hid_device *hid)
|
720 | 736 |
|
721 | 737 | usb_autopm_put_interface(usbhid->intf);
|
722 | 738 |
|
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 |
| - |
734 | 739 | Done:
|
735 | 740 | mutex_unlock(&usbhid->mutex);
|
736 | 741 | return res;
|
|
0 commit comments