Skip to content

Commit

Permalink
usb: usbtest: use irqsave() in USB's complete callback
Browse files Browse the repository at this point in the history
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Jul 26, 2018
1 parent bf594c1 commit ee9a4ae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/usb/misc/usbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,12 @@ static void ctrl_complete(struct urb *urb)
struct usb_ctrlrequest *reqp;
struct subcase *subcase;
int status = urb->status;
unsigned long flags;

reqp = (struct usb_ctrlrequest *)urb->setup_packet;
subcase = container_of(reqp, struct subcase, setup);

spin_lock(&ctx->lock);
spin_lock_irqsave(&ctx->lock, flags);
ctx->count--;
ctx->pending--;

Expand Down Expand Up @@ -1185,7 +1186,7 @@ static void ctrl_complete(struct urb *urb)
/* signal completion when nothing's queued */
if (ctx->pending == 0)
complete(&ctx->complete);
spin_unlock(&ctx->lock);
spin_unlock_irqrestore(&ctx->lock, flags);
}

static int
Expand Down Expand Up @@ -1917,8 +1918,9 @@ struct transfer_context {
static void complicated_callback(struct urb *urb)
{
struct transfer_context *ctx = urb->context;
unsigned long flags;

spin_lock(&ctx->lock);
spin_lock_irqsave(&ctx->lock, flags);
ctx->count--;

ctx->packet_count += urb->number_of_packets;
Expand Down Expand Up @@ -1958,7 +1960,7 @@ static void complicated_callback(struct urb *urb)
complete(&ctx->done);
}
done:
spin_unlock(&ctx->lock);
spin_unlock_irqrestore(&ctx->lock, flags);
}

static struct urb *iso_alloc_urb(
Expand Down

0 comments on commit ee9a4ae

Please sign in to comment.