drivers/usb: use lock to protect reqbuf when cdcacm unbind When CONFIG_CDCACM_DISABLE_TXBUF is enabled, if the USB is unplugged during serial data transmission, it is possible that cdcacm will enter the unbind process, and reqbuf will be released, causing a crash during serial write. Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index 73c7bc0..2858ee1 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c
@@ -1497,6 +1497,10 @@ * of them) */ +#ifdef CONFIG_CDCACM_DISABLE_TXBUF + nxmutex_lock(&priv->serdev.xmit.lock); +#endif + flags = spin_lock_irqsave(&priv->lock); #ifdef CONFIG_CDCACM_DISABLE_TXBUF @@ -1524,6 +1528,10 @@ DEBUGASSERT(priv->nwrq == 0); spin_unlock_irqrestore(&priv->lock, flags); +#ifdef CONFIG_CDCACM_DISABLE_TXBUF + nxmutex_unlock(&priv->serdev.xmit.lock); +#endif + #ifdef CONFIG_CDCACM_HAVE_EPINTIN /* Free the interrupt IN endpoint */