From 5fc0405a6f9521bf16121265902bf247b8af209d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Thu, 12 Sep 2024 08:50:03 +0200 Subject: [PATCH] drivers: usb: udc_dwc2: Synchronize thread with UDC API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UDC API handlers and DWC2 driver thread share not only software constructs, but also the underlying hardware. Ensure that any UDC API call is not preempted by DWC2 driver thread (and vice versa) by acquiring the lock in thread handler. Signed-off-by: Tomasz Moń --- drivers/usb/udc/udc_dwc2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/udc/udc_dwc2.c b/drivers/usb/udc/udc_dwc2.c index 4a8abafb957..fcdb22afdb1 100644 --- a/drivers/usb/udc/udc_dwc2.c +++ b/drivers/usb/udc/udc_dwc2.c @@ -2722,6 +2722,8 @@ static ALWAYS_INLINE void dwc2_thread_handler(void *const arg) */ evt = k_event_wait(&priv->drv_evt, UINT32_MAX, false, K_FOREVER); + udc_lock_internal(dev, K_FOREVER); + if (evt & BIT(DWC2_DRV_EVT_XFER)) { k_event_clear(&priv->drv_evt, BIT(DWC2_DRV_EVT_XFER)); @@ -2794,6 +2796,8 @@ static ALWAYS_INLINE void dwc2_thread_handler(void *const arg) config->irq_enable_func(dev); } + + udc_unlock_internal(dev); } static const struct udc_api udc_dwc2_api = {