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>
This commit is contained in:
yangsong8
2025-08-21 10:36:36 +08:00
committed by Xiang Xiao
parent a53223741e
commit 10180ab4eb
+8
View File
@@ -1497,6 +1497,10 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
* 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 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
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 */