drivers/usbdev: fix double free when cdcacm uninitialize with not used

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2024-01-12 15:48:16 +08:00 committed by Xiang Xiao
parent ad59ef075f
commit e5a925543b
2 changed files with 6 additions and 13 deletions

View File

@ -3071,6 +3071,10 @@ void cdcacm_uninitialize(FAR struct usbdevclass_driver_s *classdev)
char devname[CDCACM_DEVNAME_SIZE];
int ret;
#ifndef CONFIG_CDCACM_COMPOSITE
usbdev_unregister(&drvr->drvr);
#endif
/* Un-register the CDC/ACM TTY device */
snprintf(devname, CDCACM_DEVNAME_SIZE, CDCACM_DEVNAME_FORMAT, priv->minor);
@ -3080,18 +3084,6 @@ void cdcacm_uninitialize(FAR struct usbdevclass_driver_s *classdev)
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_UARTUNREGISTER),
(uint16_t)-ret);
}
#ifndef CONFIG_CDCACM_COMPOSITE
usbdev_unregister(&drvr->drvr);
#endif
/* And free the memory resources. */
if (priv->serdev.open_count <= 0)
{
wd_cancel(&priv->rxfailsafe);
kmm_free(priv);
}
}
/****************************************************************************

View File

@ -312,6 +312,8 @@ enum cdcacm_event_e
typedef CODE void (*cdcacm_callback_t)(enum cdcacm_event_e event);
struct usbdevclass_driver_s;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -336,7 +338,6 @@ typedef CODE void (*cdcacm_callback_t)(enum cdcacm_event_e event);
#if defined(CONFIG_USBDEV_COMPOSITE) && defined(CONFIG_CDCACM_COMPOSITE)
struct usbdev_devinfo_s;
struct usbdevclass_driver_s;
int cdcacm_classobject(int minor, FAR struct usbdev_devinfo_s *devinfo,
FAR struct usbdevclass_driver_s **classdev);
#endif