Skip to content

Commit

Permalink
drivers/usbdev/cdcacm.c: Fix a crash in cdcacm if usbdev gets unregis…
Browse files Browse the repository at this point in the history
…tered while client calls close for the tty

Make sure that the cdcacm is disconnected before the usbdev gets unregistered.

Also, check if the device is connected or not in cdcuart_txempty (uart_txempty). Otherwise there may be a crash during uart_tcdrain, called in tty close path, if the usbdev unregistration happens during the loop.

This issue can be triggered by monitoring the cable connection status in one thread, sending BOARDIOC_USBDEV_DISCONNECT if the usb cable is detached. In another thread close the ttyACM.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Jan 10, 2025
1 parent 67a371b commit 605ebe5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/usbdev/cdcacm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,13 @@ static bool cdcuart_txempty(FAR struct uart_dev_s *dev)
#endif

flags = enter_critical_section();

if (dev->disconnected)
{
leave_critical_section(flags);
return true;
}

priv->ispolling = true;
EP_POLL(ep);
priv->ispolling = false;
Expand Down Expand Up @@ -3012,6 +3019,10 @@ void cdcacm_uninitialize(FAR struct usbdevclass_driver_s *classdev)
char devname[CDCACM_DEVNAME_SIZE];
int ret;

/* Disconnect in case we are connected */

cdcacm_disconnect(classdev, priv->usbdev);

#ifndef CONFIG_CDCACM_COMPOSITE
usbdev_unregister(&drvr->drvr);
#endif
Expand Down

0 comments on commit 605ebe5

Please sign in to comment.