Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1388082
| From | Kamal Mostafa <kamal@canonical.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 3.19.y-ckt 20/66] HID: usbhid: fix inconsistent reset/resume/reset-resume behavior |
| Date | 2016-04-26 22:50 +0200 |
| Message-ID | <rsi5J-5Mq-45@gated-at.bofh.it> (permalink) |
| References | <rshMl-5Dx-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
3.19.8-ckt20 -stable review patch. If anyone has any objections, please let me know.
---8<------------------------------------------------------------
From: Alan Stern <stern@rowland.harvard.edu>
commit 972e6a993f278b416a8ee3ec65475724fc36feb2 upstream.
The usbhid driver has inconsistently duplicated code in its post-reset,
resume, and reset-resume pathways.
reset-resume doesn't check HID_STARTED before trying to
restart the I/O queues.
resume fails to clear the HID_SUSPENDED flag if HID_STARTED
isn't set.
resume calls usbhid_restart_queues() with usbhid->lock held
and the others call it without holding the lock.
The first item in particular causes a problem following a reset-resume
if the driver hasn't started up its I/O. URB submission fails because
usbhid->urbin is NULL, and this triggers an unending reset-retry loop.
This patch fixes the problem by creating a new subroutine,
hid_restart_io(), to carry out all the common activities. It also
adds some checks that were missing in the original code:
After a reset, there's no need to clear any halted endpoints.
After a resume, if a reset is pending there's no need to
restart any I/O until the reset is finished.
After a resume, if the interrupt-IN endpoint is halted there's
no need to submit the input URB until the halt has been
cleared.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: Daniel Fraga <fragabr@gmail.com>
Tested-by: Daniel Fraga <fragabr@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
drivers/hid/usbhid/hid-core.c | 73 ++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index eab5bd6..dd534c6 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -950,14 +950,6 @@ static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count)
return ret;
}
-static void usbhid_restart_queues(struct usbhid_device *usbhid)
-{
- if (usbhid->urbout && !test_bit(HID_OUT_RUNNING, &usbhid->iofl))
- usbhid_restart_out_queue(usbhid);
- if (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
- usbhid_restart_ctrl_queue(usbhid);
-}
-
static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
{
struct usbhid_device *usbhid = hid->driver_data;
@@ -1403,6 +1395,37 @@ static void hid_cease_io(struct usbhid_device *usbhid)
usb_kill_urb(usbhid->urbout);
}
+static void hid_restart_io(struct hid_device *hid)
+{
+ struct usbhid_device *usbhid = hid->driver_data;
+ int clear_halt = test_bit(HID_CLEAR_HALT, &usbhid->iofl);
+ int reset_pending = test_bit(HID_RESET_PENDING, &usbhid->iofl);
+
+ spin_lock_irq(&usbhid->lock);
+ clear_bit(HID_SUSPENDED, &usbhid->iofl);
+ usbhid_mark_busy(usbhid);
+
+ if (clear_halt || reset_pending)
+ schedule_work(&usbhid->reset_work);
+ usbhid->retry_delay = 0;
+ spin_unlock_irq(&usbhid->lock);
+
+ if (reset_pending || !test_bit(HID_STARTED, &usbhid->iofl))
+ return;
+
+ if (!clear_halt) {
+ if (hid_start_in(hid) < 0)
+ hid_io_error(hid);
+ }
+
+ spin_lock_irq(&usbhid->lock);
+ if (usbhid->urbout && !test_bit(HID_OUT_RUNNING, &usbhid->iofl))
+ usbhid_restart_out_queue(usbhid);
+ if (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
+ usbhid_restart_ctrl_queue(usbhid);
+ spin_unlock_irq(&usbhid->lock);
+}
+
/* Treat USB reset pretty much the same as suspend/resume */
static int hid_pre_reset(struct usb_interface *intf)
{
@@ -1452,14 +1475,14 @@ static int hid_post_reset(struct usb_interface *intf)
return 1;
}
+ /* No need to do another reset or clear a halted endpoint */
spin_lock_irq(&usbhid->lock);
clear_bit(HID_RESET_PENDING, &usbhid->iofl);
+ clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
spin_unlock_irq(&usbhid->lock);
hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
- status = hid_start_in(hid);
- if (status < 0)
- hid_io_error(hid);
- usbhid_restart_queues(usbhid);
+
+ hid_restart_io(hid);
return 0;
}
@@ -1482,25 +1505,9 @@ void usbhid_put_power(struct hid_device *hid)
#ifdef CONFIG_PM
static int hid_resume_common(struct hid_device *hid, bool driver_suspended)
{
- struct usbhid_device *usbhid = hid->driver_data;
- int status;
-
- spin_lock_irq(&usbhid->lock);
- clear_bit(HID_SUSPENDED, &usbhid->iofl);
- usbhid_mark_busy(usbhid);
-
- if (test_bit(HID_CLEAR_HALT, &usbhid->iofl) ||
- test_bit(HID_RESET_PENDING, &usbhid->iofl))
- schedule_work(&usbhid->reset_work);
- usbhid->retry_delay = 0;
-
- usbhid_restart_queues(usbhid);
- spin_unlock_irq(&usbhid->lock);
-
- status = hid_start_in(hid);
- if (status < 0)
- hid_io_error(hid);
+ int status = 0;
+ hid_restart_io(hid);
if (driver_suspended && hid->driver && hid->driver->resume)
status = hid->driver->resume(hid);
return status;
@@ -1569,12 +1576,8 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
static int hid_resume(struct usb_interface *intf)
{
struct hid_device *hid = usb_get_intfdata (intf);
- struct usbhid_device *usbhid = hid->driver_data;
int status;
- if (!test_bit(HID_STARTED, &usbhid->iofl))
- return 0;
-
status = hid_resume_common(hid, true);
dev_dbg(&intf->dev, "resume status %d\n", status);
return 0;
@@ -1583,10 +1586,8 @@ static int hid_resume(struct usb_interface *intf)
static int hid_reset_resume(struct usb_interface *intf)
{
struct hid_device *hid = usb_get_intfdata(intf);
- struct usbhid_device *usbhid = hid->driver_data;
int status;
- clear_bit(HID_SUSPENDED, &usbhid->iofl);
status = hid_post_reset(intf);
if (status >= 0 && hid->driver && hid->driver->reset_resume) {
int ret = hid->driver->reset_resume(hid);
--
2.7.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[3.19.y-ckt stable] Linux 3.19.8-ckt20 stable review Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 09/66] net: validate variable length ll headers Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 53/66] x86/mm/xen: Suppress hugetlbfs in PV guests Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 63/66] Input: pmic8xxx-pwrkey - fix algorithm for converting trigger delay Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 45/66] drm/radeon: add a quirk for a XFX R9 270X Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 62/66] net: bcmgenet: device stats are unsigned long Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 21/66] ARM: OMAP2+: hwmod: Fix updating of sysconfig register Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:30 +0200 [PATCH 3.19.y-ckt 38/66] crypto: sha1-mb - use corrcet pointer while completing jobs Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 44/66] powerpc: Update TM user feature bits in scan_features() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 18/66] ipv4: l2tp: fix a potential issue in l2tp_ip_recv Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 33/66] usb: xhci: fix wild pointers in xhci_mem_cleanup Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 39/66] crypto: ccp - Prevent information leakage on export Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 43/66] powerpc: Update cpu_user_features2 in scan_features() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 48/66] ALSA: pcxhr: Fix missing mutex unlock Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 47/66] futex: Acknowledge a new waiter in counter before plist Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 36/66] USB: uas: Add a new NO_REPORT_LUNS quirk Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 50/66] drm/radeon: forbid mapping of userptr bo through radeon device file Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 34/66] usb: xhci: fix xhci locking up during hcd remove Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 46/66] futex: Handle unlock_pi race gracefully Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 30/66] usb: xhci: applying XHCI_PME_STUCK_QUIRK to Intel BXT B0 host Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 35/66] xhci: fix 10 second timeout on removal of PCI hotpluggable xhci controllers Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 27/66] ALSA: hda - Fix regression of monitor_present flag in eld proc file Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 22/66] drm/qxl: fix cursor position with non-zero hotspot Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 42/66] powerpc: scan_features() updates incorrect bits for REAL_LE Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 23/66] Input: gtco - fix crash on detecting device without endpoints Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 41/66] ALSA: hda/realtek - Add ALC3234 headset mode for Optiplex 9020m Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 59/66] bpf/verifier: reject invalid LD_ABS | BPF_DW instruction Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 31/66] xhci: resume USB 3 roothub first Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 37/66] usb: hcd: out of bounds access in for_each_companion Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 32/66] usb: host: xhci: add a new quirk XHCI_NO_64BIT_SUPPORT Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 29/66] lib: lz4: fixed zram with lz4 on big endian machines Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 40/66] video: ARM CLCD: runtime check for Versatile Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 26/66] nl80211: check netlink protocol in socket release notification Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 28/66] dmaengine: dw: fix master selection Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 25/66] ALSA: usb-audio: Skip volume controls triggers hangup on Dell USB Dock Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:40 +0200 [PATCH 3.19.y-ckt 08/66] udp6: fix UDP/IPv6 encap resubmit path Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 11/66] macvtap: always pass ethernet header in linear Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 16/66] qmi_wwan: add "D-Link DWM-221 B1" device id Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 10/66] sh_eth: fix NULL pointer dereference in sh_eth_ring_format() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 01/66] usbnet: cleanup after bind() in probe() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 05/66] sctp: lack the check for ports in sctp_v6_cmp_addr Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 02/66] tunnel: Clear IPCB(skb)->opt before dst_link_failure called Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 04/66] net: qca_spi: clear IFF_TX_SKB_SHARING Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 17/66] rtnl: fix msg size calculation in if_nlmsg_size() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 15/66] xfrm: Fix crash observed during device unregistration and decryption Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 20/66] HID: usbhid: fix inconsistent reset/resume/reset-resume behavior Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 14/66] bonding: fix bond_get_stats() Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 07/66] cdc_ncm: toggle altsetting to force reset before setup Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 19/66] ipv6: l2tp: fix a potential issue in l2tp_ip6_recv Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 12/66] farsync: fix off-by-one bug in fst_add_one Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200 [PATCH 3.19.y-ckt 06/66] qmi_wwan: add Sierra Wireless EM74xx device ID Kamal Mostafa <kamal@canonical.com> - 2016-04-26 22:50 +0200
csiph-web