mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
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:
@@ -1497,6 +1497,10 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
|
|||||||
* of them)
|
* of them)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_CDCACM_DISABLE_TXBUF
|
||||||
|
nxmutex_lock(&priv->serdev.xmit.lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&priv->lock);
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
|
|
||||||
#ifdef CONFIG_CDCACM_DISABLE_TXBUF
|
#ifdef CONFIG_CDCACM_DISABLE_TXBUF
|
||||||
@@ -1524,6 +1528,10 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
|
|||||||
DEBUGASSERT(priv->nwrq == 0);
|
DEBUGASSERT(priv->nwrq == 0);
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
|
#ifdef CONFIG_CDCACM_DISABLE_TXBUF
|
||||||
|
nxmutex_unlock(&priv->serdev.xmit.lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CDCACM_HAVE_EPINTIN
|
#ifdef CONFIG_CDCACM_HAVE_EPINTIN
|
||||||
/* Free the interrupt IN endpoint */
|
/* Free the interrupt IN endpoint */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user