usb: core: use irqsave() in sg_complete() complete callback
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Sun, 24 Jun 2018 22:08:36 +0000 (00:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Jun 2018 10:36:06 +0000 (19:36 +0900)
The USB completion callback does not disable interrupts while acquiring
the lock. We want to remove the local_irq_disable() invocation from
__usb_hcd_giveback_urb() and therefore it is required for the callback
handler to disable the interrupts while acquiring the lock.
The callback may be invoked either in IRQ or BH context depending on the
USB host controller.
Use the _irqsave() variant of the locking primitives.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/message.c

index 1a15392..228672f 100644 (file)
@@ -269,10 +269,11 @@ static void sg_clean(struct usb_sg_request *io)
 
 static void sg_complete(struct urb *urb)
 {
+       unsigned long flags;
        struct usb_sg_request *io = urb->context;
        int status = urb->status;
 
-       spin_lock(&io->lock);
+       spin_lock_irqsave(&io->lock, flags);
 
        /* In 2.5 we require hcds' endpoint queues not to progress after fault
         * reports, until the completion callback (this!) returns.  That lets
@@ -306,7 +307,7 @@ static void sg_complete(struct urb *urb)
                 * unlink pending urbs so they won't rx/tx bad data.
                 * careful: unlink can sometimes be synchronous...
                 */
-               spin_unlock(&io->lock);
+               spin_unlock_irqrestore(&io->lock, flags);
                for (i = 0, found = 0; i < io->entries; i++) {
                        if (!io->urbs[i])
                                continue;
@@ -323,7 +324,7 @@ static void sg_complete(struct urb *urb)
                        } else if (urb == io->urbs[i])
                                found = 1;
                }
-               spin_lock(&io->lock);
+               spin_lock_irqsave(&io->lock, flags);
        }
 
        /* on the last completion, signal usb_sg_wait() */
@@ -332,7 +333,7 @@ static void sg_complete(struct urb *urb)
        if (!io->count)
                complete(&io->complete);
 
-       spin_unlock(&io->lock);
+       spin_unlock_irqrestore(&io->lock, flags);
 }