This reverts commit ed194d1367698a0872a2b75bbe06b3932ce9df3a.

In contrast to the original patch description, apparently not all handlers
were audited properly. E.g. my RT5370 based USB WIFI adapter (driver in
drivers/net/wireless/ralink/rt2x00) hangs after a while under heavy load.
This revert fixes this.

Also revert the follow-up patch d6142b91e9cc249b3aa22c90fade67e2e2d52cdb
("usb: core: remove flags variable in __usb_hcd_giveback_urb()"), since now
we need the flags variable again.

Cc: Sebastian Andrzej Siewior <bige...@linutronix.de>
Cc: Alan Stern <st...@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: linux-...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org # 4.20+
Signed-off-by: Soeren Moch <sm...@web.de>
---
 drivers/usb/core/hcd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 94d22551fc1b..08d25fcf8b8e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1739,6 +1739,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
        struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
        struct usb_anchor *anchor = urb->anchor;
        int status = urb->unlinked;
+       unsigned long flags;

        urb->hcpriv = NULL;
        if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
@@ -1755,7 +1756,20 @@ static void __usb_hcd_giveback_urb(struct urb *urb)

        /* pass ownership to the completion handler */
        urb->status = status;
+
+       /*
+        * We disable local IRQs here avoid possible deadlock because
+        * drivers may call spin_lock() to hold lock which might be
+        * acquired in one hard interrupt handler.
+        *
+        * The local_irq_save()/local_irq_restore() around complete()
+        * will be removed if current USB drivers have been cleaned up
+        * and no one may trigger the above deadlock situation when
+        * running complete() in tasklet.
+        */
+       local_irq_save(flags);
        urb->complete(urb);
+       local_irq_restore(flags);

        usb_anchor_resume_wakeups(anchor);
        atomic_dec(&urb->use_count);
--
2.17.1

Reply via email to