Commit cb53a4e0 authored by Yoshihiro Shimoda's avatar Yoshihiro Shimoda Committed by Greg Kroah-Hartman

usb: gadget: udc: renesas_usb3: lock for PN_ registers access

commit 940f538a upstream.

This controller disallows to change the PIPE until reading/writing
a packet finishes. However. the previous code is not enough to hold
the lock in some functions. So, this patch fixes it.

Fixes: 746bfe63 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 peripheral controller")
Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent dd65c095
...@@ -1401,7 +1401,13 @@ static void usb3_request_done_pipen(struct renesas_usb3 *usb3, ...@@ -1401,7 +1401,13 @@ static void usb3_request_done_pipen(struct renesas_usb3 *usb3,
struct renesas_usb3_request *usb3_req, struct renesas_usb3_request *usb3_req,
int status) int status)
{ {
usb3_pn_stop(usb3); unsigned long flags;
spin_lock_irqsave(&usb3->lock, flags);
if (usb3_pn_change(usb3, usb3_ep->num))
usb3_pn_stop(usb3);
spin_unlock_irqrestore(&usb3->lock, flags);
usb3_disable_pipe_irq(usb3, usb3_ep->num); usb3_disable_pipe_irq(usb3, usb3_ep->num);
usb3_request_done(usb3_ep, usb3_req, status); usb3_request_done(usb3_ep, usb3_req, status);
...@@ -1430,30 +1436,46 @@ static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) ...@@ -1430,30 +1436,46 @@ static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num)
{ {
struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num);
struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep);
bool done = false;
if (!usb3_req) if (!usb3_req)
return; return;
spin_lock(&usb3->lock);
if (usb3_pn_change(usb3, num))
goto out;
if (usb3_ep->dir_in) { if (usb3_ep->dir_in) {
/* Do not stop the IN pipe here to detect LSTTR interrupt */ /* Do not stop the IN pipe here to detect LSTTR interrupt */
if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE)) if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE))
usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA);
} else { } else {
if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ)) if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ))
usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); done = true;
} }
out:
/* need to unlock because usb3_request_done_pipen() locks it */
spin_unlock(&usb3->lock);
if (done)
usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0);
} }
static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num)
{ {
u32 pn_int_sta; u32 pn_int_sta;
if (usb3_pn_change(usb3, num) < 0) spin_lock(&usb3->lock);
if (usb3_pn_change(usb3, num) < 0) {
spin_unlock(&usb3->lock);
return; return;
}
pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA);
pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA);
usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA);
spin_unlock(&usb3->lock);
if (pn_int_sta & PN_INT_LSTTR) if (pn_int_sta & PN_INT_LSTTR)
usb3_irq_epc_pipen_lsttr(usb3, num); usb3_irq_epc_pipen_lsttr(usb3, num);
if (pn_int_sta & PN_INT_BFRDY) if (pn_int_sta & PN_INT_BFRDY)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment