Skip to content

Commit 2587a02

Browse files
Peter Chenfelipebalbi
authored andcommitted
usb: cdns3: ep0: add spinlock for cdns3_check_new_setup
The other thread may access other endpoints when the cdns3_check_new_setup is handling, add spinlock to protect it. Cc: <[email protected]> Fixes: 7733f6c ("usb: cdns3: Add Cadence USB3 DRD Driver") Reviewed-by: Pawel Laszczak <[email protected]> Signed-off-by: Peter Chen <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent ba3a80f commit 2587a02

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/usb/cdns3/ep0.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,17 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
705705
int ret = 0;
706706
u8 zlp = 0;
707707

708+
spin_lock_irqsave(&priv_dev->lock, flags);
708709
trace_cdns3_ep0_queue(priv_dev, request);
709710

710711
/* cancel the request if controller receive new SETUP packet. */
711-
if (cdns3_check_new_setup(priv_dev))
712+
if (cdns3_check_new_setup(priv_dev)) {
713+
spin_unlock_irqrestore(&priv_dev->lock, flags);
712714
return -ECONNRESET;
715+
}
713716

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

719721
erdy_sent = !priv_dev->hw_configured_flag;
@@ -738,7 +740,6 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
738740
return 0;
739741
}
740742

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

0 commit comments

Comments
 (0)