Commit b905811a authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: usbhid: prevent unwanted events to be sent when re-opening the device

When events occurs while no one is listening to the node (hid->open == 0
and usb_kill_urb() called) some events are still stacked somewhere in
the USB (kernel or device?) stack. When the node gets reopened, these
events are drained, and this results in spurious touch down/up, or mouse
button clicks.

The problem was spotted with touchscreens in fdo bug #81781 [1], but it
actually occurs with any mouse using hid-generic or touchscreen.

A way to reproduce it is to call:

$ xinput disable 9 ; sleep 5 ; xinput enable 9

With 9 being the device ID for the touchscreen/mouse. During the "sleep",
produce some touch events or click events. When "xinput enable" is called,
at least one click is generated.

This patch tries to fix this by draining the queue for 50 msec and
during this time frame, not forwarding these old events to the hid layer.

Hans completed the explanation:
"""
Devices like mice (basically any hid device) will have a fifo
on the device side, when we stop submitting urbs to get hid reports from
it, that fifo will fill up, and when we resume we will get whatever
is there in that fifo.
"""

[1] https://bugs.freedesktop.org/show_bug.cgi?id=81781Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 9578f41a
...@@ -278,6 +278,7 @@ static void hid_irq_in(struct urb *urb) ...@@ -278,6 +278,7 @@ static void hid_irq_in(struct urb *urb)
usbhid->retry_delay = 0; usbhid->retry_delay = 0;
if ((hid->quirks & HID_QUIRK_ALWAYS_POLL) && !hid->open) if ((hid->quirks & HID_QUIRK_ALWAYS_POLL) && !hid->open)
break; break;
if (!test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) {
hid_input_report(urb->context, HID_INPUT_REPORT, hid_input_report(urb->context, HID_INPUT_REPORT,
urb->transfer_buffer, urb->transfer_buffer,
urb->actual_length, 1); urb->actual_length, 1);
...@@ -290,6 +291,7 @@ static void hid_irq_in(struct urb *urb) ...@@ -290,6 +291,7 @@ static void hid_irq_in(struct urb *urb)
set_bit(HID_KEYS_PRESSED, &usbhid->iofl); set_bit(HID_KEYS_PRESSED, &usbhid->iofl);
else else
clear_bit(HID_KEYS_PRESSED, &usbhid->iofl); clear_bit(HID_KEYS_PRESSED, &usbhid->iofl);
}
break; break;
case -EPIPE: /* stall */ case -EPIPE: /* stall */
usbhid_mark_busy(usbhid); usbhid_mark_busy(usbhid);
...@@ -688,6 +690,7 @@ int usbhid_open(struct hid_device *hid) ...@@ -688,6 +690,7 @@ int usbhid_open(struct hid_device *hid)
goto done; goto done;
} }
usbhid->intf->needs_remote_wakeup = 1; usbhid->intf->needs_remote_wakeup = 1;
set_bit(HID_RESUME_RUNNING, &usbhid->iofl);
res = hid_start_in(hid); res = hid_start_in(hid);
if (res) { if (res) {
if (res != -ENOSPC) { if (res != -ENOSPC) {
...@@ -701,6 +704,15 @@ int usbhid_open(struct hid_device *hid) ...@@ -701,6 +704,15 @@ int usbhid_open(struct hid_device *hid)
} }
} }
usb_autopm_put_interface(usbhid->intf); usb_autopm_put_interface(usbhid->intf);
/*
* In case events are generated while nobody was listening,
* some are released when the device is re-opened.
* Wait 50 msec for the queue to empty before allowing events
* to go through hid.
*/
msleep(50);
clear_bit(HID_RESUME_RUNNING, &usbhid->iofl);
} }
done: done:
mutex_unlock(&hid_open_mut); mutex_unlock(&hid_open_mut);
......
...@@ -52,6 +52,7 @@ struct usb_interface *usbhid_find_interface(int minor); ...@@ -52,6 +52,7 @@ struct usb_interface *usbhid_find_interface(int minor);
#define HID_STARTED 8 #define HID_STARTED 8
#define HID_KEYS_PRESSED 10 #define HID_KEYS_PRESSED 10
#define HID_NO_BANDWIDTH 11 #define HID_NO_BANDWIDTH 11
#define HID_RESUME_RUNNING 12
/* /*
* USB-specific HID struct, to be pointed to * USB-specific HID struct, to be pointed to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment