OSDN Git Service

usb: cdc-wdm: use irqsave() in USB's complete callback
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Sun, 24 Jun 2018 22:08:35 +0000 (00:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Jun 2018 10:36:07 +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.

Cc: Oliver Neukum <oneukum@suse.com>
Cc: "Bjørn Mork" <bjorn@mork.no>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/class/cdc-wdm.c

index 203bbd3..bec581f 100644 (file)
@@ -142,10 +142,12 @@ found:
 static void wdm_out_callback(struct urb *urb)
 {
        struct wdm_device *desc;
+       unsigned long flags;
+
        desc = urb->context;
-       spin_lock(&desc->iuspin);
+       spin_lock_irqsave(&desc->iuspin, flags);
        desc->werr = urb->status;
-       spin_unlock(&desc->iuspin);
+       spin_unlock_irqrestore(&desc->iuspin, flags);
        kfree(desc->outbuf);
        desc->outbuf = NULL;
        clear_bit(WDM_IN_USE, &desc->flags);
@@ -154,11 +156,12 @@ static void wdm_out_callback(struct urb *urb)
 
 static void wdm_in_callback(struct urb *urb)
 {
+       unsigned long flags;
        struct wdm_device *desc = urb->context;
        int status = urb->status;
        int length = urb->actual_length;
 
-       spin_lock(&desc->iuspin);
+       spin_lock_irqsave(&desc->iuspin, flags);
        clear_bit(WDM_RESPONDING, &desc->flags);
 
        if (status) {
@@ -220,11 +223,12 @@ skip_error:
                set_bit(WDM_READ, &desc->flags);
                wake_up(&desc->wait);
        }
-       spin_unlock(&desc->iuspin);
+       spin_unlock_irqrestore(&desc->iuspin, flags);
 }
 
 static void wdm_int_callback(struct urb *urb)
 {
+       unsigned long flags;
        int rv = 0;
        int responding;
        int status = urb->status;
@@ -284,7 +288,7 @@ static void wdm_int_callback(struct urb *urb)
                goto exit;
        }
 
-       spin_lock(&desc->iuspin);
+       spin_lock_irqsave(&desc->iuspin, flags);
        responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
        if (!desc->resp_count++ && !responding
                && !test_bit(WDM_DISCONNECTING, &desc->flags)
@@ -292,7 +296,7 @@ static void wdm_int_callback(struct urb *urb)
                rv = usb_submit_urb(desc->response, GFP_ATOMIC);
                dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv);
        }
-       spin_unlock(&desc->iuspin);
+       spin_unlock_irqrestore(&desc->iuspin, flags);
        if (rv < 0) {
                clear_bit(WDM_RESPONDING, &desc->flags);
                if (rv == -EPERM)