Skip to content

Commit

Permalink
usb: cdns3: ep0: add spinlock for cdns3_check_new_setup
Browse files Browse the repository at this point in the history
The other thread may access other endpoints when the cdns3_check_new_setup
is handling, add spinlock to protect it.

Fixes: 7733f6c ("usb: cdns3: Add Cadence USB3 DRD Driver")
Cc: <[email protected]>
Reviewed-by: Pawel Laszczak <[email protected]>
Signed-off-by: Peter Chen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Peter Chen committed Aug 5, 2020
1 parent 9169101 commit 3979e33
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/usb/cdns3/ep0.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,16 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
priv_dev->ep0_data_dir ? "IN" : "OUT",
request->length);

spin_lock_irqsave(&priv_dev->lock, flags);

/* cancel the request if controller receive new SETUP packet. */
if (cdns3_check_new_setup(priv_dev))
if (cdns3_check_new_setup(priv_dev)) {
spin_unlock_irqrestore(&priv_dev->lock, flags);
return -ECONNRESET;
}

/* send STATUS stage. Should be called only for SET_CONFIGURATION */
if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) {
spin_lock_irqsave(&priv_dev->lock, flags);
cdns3_select_ep(priv_dev, 0x00);

erdy_sent = !priv_dev->hw_configured_flag;
Expand All @@ -793,7 +796,6 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
return 0;
}

spin_lock_irqsave(&priv_dev->lock, flags);
if (!list_empty(&priv_ep->pending_req_list)) {
dev_err(priv_dev->dev,
"can't handle multiple requests for ep0\n");
Expand Down

0 comments on commit 3979e33

Please sign in to comment.