linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: gadget: Avoid race between dwc3 interrupt handler and irq thread handler
@ 2016-12-26  8:01 Baolin Wang
  2016-12-27  2:39 ` Lu Baolu
  2016-12-27 10:52 ` Janusz Dziedzic
  0 siblings, 2 replies; 23+ messages in thread
From: Baolin Wang @ 2016-12-26  8:01 UTC (permalink / raw)
  To: balbi, gregkh
  Cc: linux-usb, linux-kernel, linaro-kernel, broonie, baolin.wang

On some platfroms(like x86 platform), when one core is running the USB gadget
irq thread handler by dwc3_thread_interrupt(), meanwhile another core also can
respond other interrupts from dwc3 controller and modify the event buffer by
dwc3_interrupt() function, that will cause getting the wrong event count in
irq thread handler to make the USB function abnormal.

We should add spin_lock/unlock() in dwc3_check_event_buf() to avoid this race.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/usb/dwc3/gadget.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 6785595..1a1e1f4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2894,10 +2894,13 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)
 		return IRQ_HANDLED;
 	}
 
+	spin_lock(&dwc->lock);
 	count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
 	count &= DWC3_GEVNTCOUNT_MASK;
-	if (!count)
+	if (!count) {
+		spin_unlock(&dwc->lock);
 		return IRQ_NONE;
+	}
 
 	evt->count = count;
 	evt->flags |= DWC3_EVENT_PENDING;
@@ -2914,6 +2917,7 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)
 		memcpy(evt->cache, evt->buf, count - amount);
 
 	dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count);
+	spin_unlock(&dwc->lock);
 
 	return IRQ_WAKE_THREAD;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2017-01-06  2:44 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-26  8:01 [PATCH] usb: dwc3: gadget: Avoid race between dwc3 interrupt handler and irq thread handler Baolin Wang
2016-12-27  2:39 ` Lu Baolu
2016-12-27  2:58   ` Baolin Wang
2016-12-27  4:45     ` Lu Baolu
2016-12-27 11:05   ` Felipe Balbi
2016-12-28 15:27     ` Janusz Dziedzic
2016-12-28 16:19       ` Felipe Balbi
2016-12-29  1:29         ` John Youn
2017-01-05 19:08           ` John Youn
2017-01-06  2:44             ` Baolin Wang
2016-12-27 10:52 ` Janusz Dziedzic
2016-12-27 11:06   ` Baolin Wang
2016-12-27 11:11     ` Felipe Balbi
2016-12-27 12:16       ` Baolin Wang
2016-12-28 12:30         ` Janusz Dziedzic
2017-01-03 12:21           ` Baolin Wang
2017-01-03 12:33             ` Felipe Balbi
2017-01-05  2:07               ` Baolin Wang
2017-01-05  9:26                 ` Felipe Balbi
2017-01-05  9:43                   ` Baolin Wang
2017-01-05 11:19                     ` Felipe Balbi
2017-01-05 12:03                       ` Baolin Wang
2016-12-27 11:07   ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).