From b4f6a3a8788ed39a48bfe155f8b1a17bcbdd5d41 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Tue, 8 Oct 2019 08:01:30 -0600 Subject: [PATCH] drivers/usbdev/cdcacm.c: Fix memory leak of RX failsafe timer. --- boards/xtensa/esp32/esp32-core/README.txt | 2 +- drivers/usbdev/cdcacm.c | 11 ++++++----- drivers/usbdev/pl2303.c | 2 +- drivers/usbdev/rndis.c | 2 +- drivers/usbdev/usbmsc.c | 2 +- include/nuttx/usb/cdcacm.h | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/boards/xtensa/esp32/esp32-core/README.txt b/boards/xtensa/esp32/esp32-core/README.txt index 6b6412d5546..ccf0c2896ae 100644 --- a/boards/xtensa/esp32/esp32-core/README.txt +++ b/boards/xtensa/esp32/esp32-core/README.txt @@ -696,7 +696,7 @@ NOTES: 2. 2016-12-23: Test appears to be fully functional in the single CPU mode. 3. 2016-12-24: But when SMP is enabled, there is a consistent, repeatable crash in the waitpid() test. At the time of the crash, there is - extensive memory corruption and a user exception occurrs (cause=28). + extensive memory corruption and a user exception occurs (cause=28). Things to Do ============ diff --git a/drivers/usbdev/cdcacm.c b/drivers/usbdev/cdcacm.c index f91d4fb09d2..b266b1289f6 100644 --- a/drivers/usbdev/cdcacm.c +++ b/drivers/usbdev/cdcacm.c @@ -714,7 +714,7 @@ static int cdcacm_release_rxpending(FAR struct cdcacm_dev_s *priv) /* cdcacm_recvpacket() will return OK if the entire packet was * successful buffered. In the case of RX buffer overrun, * cdcacm_recvpacket() will return a failure (-ENOSPC) and will - * set the req->offset field + * set the req->offset field. */ ret = cdcacm_recvpacket(priv, rdcontainer); @@ -1350,7 +1350,7 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, /* Pre-allocate all endpoints... the endpoints will not be functional * until the SET CONFIGURATION request is processed in cdcacm_setconfig. * This is done here because there may be calls to kmm_malloc and the SET - * CONFIGURATION processing probably occurrs within interrupt handling + * CONFIGURATION processing probably occurs within interrupt handling * logic where kmm_malloc calls will fail. */ @@ -3003,6 +3003,7 @@ int cdcacm_classobject(int minor, FAR struct usbdev_devinfo_s *devinfo, return OK; errout_with_class: + wd_delete(priv->rxfailsafe); kmm_free(alloc); return ret; } @@ -3055,11 +3056,9 @@ int cdcacm_initialize(int minor, FAR void **handle) */ devinfo.nendpoints = CDCACM_NUM_EPS; -#ifndef CONFIG_CDCACM_COMPOSITE devinfo.epno[CDCACM_EP_INTIN_IDX] = CONFIG_CDCACM_EPINTIN; devinfo.epno[CDCACM_EP_BULKIN_IDX] = CONFIG_CDCACM_EPBULKIN; devinfo.epno[CDCACM_EP_BULKOUT_IDX] = CONFIG_CDCACM_EPBULKOUT; -#endif /* Get an instance of the serial driver class object */ @@ -3138,6 +3137,7 @@ void cdcacm_uninitialize(FAR void *handle) * free the memory resources. */ + wd_delete(priv->rxfailsafe); kmm_free(priv); return; } @@ -3167,8 +3167,9 @@ void cdcacm_uninitialize(FAR void *handle) #ifndef CONFIG_CDCACM_COMPOSITE usbdev_unregister(&drvr->drvr); - /* And free the driver structure */ + /* And free the memory resources. */ + wd_delete(priv->rxfailsafe); kmm_free(priv); #else diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index 16119057903..43848649c4d 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -1356,7 +1356,7 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, /* Pre-allocate all endpoints... the endpoints will not be functional * until the SET CONFIGURATION request is processed in usbclass_setconfig. * This is done here because there may be calls to kmm_malloc and the SET - * CONFIGURATION processing probably occurrs within interrupt handling + * CONFIGURATION processing probably occurs within interrupt handling * logic where kmm_malloc calls will fail. */ diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index fe5b66a6d46..a185f802d68 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -2044,7 +2044,7 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, /* Pre-allocate all endpoints... the endpoints will not be functional * until the SET CONFIGURATION request is processed in usbclass_setconfig. * This is done here because there may be calls to kmm_malloc and the SET - * CONFIGURATION processing probably occurrs within interrupt handling + * CONFIGURATION processing probably occurs within interrupt handling * logic where kmm_malloc calls will fail. */ diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 197aed97046..e28767c8406 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -302,7 +302,7 @@ static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver, /* Pre-allocate all endpoints... the endpoints will not be functional * until the SET CONFIGURATION request is processed in usbmsc_setconfig. * This is done here because there may be calls to kmm_malloc and the SET - * CONFIGURATION processing probably occurrs within interrupt handling + * CONFIGURATION processing probably occurs within interrupt handling * logic where kmm_malloc calls will fail. */ diff --git a/include/nuttx/usb/cdcacm.h b/include/nuttx/usb/cdcacm.h index 1eab472ed9f..eba62104193 100644 --- a/include/nuttx/usb/cdcacm.h +++ b/include/nuttx/usb/cdcacm.h @@ -381,7 +381,7 @@ int cdcacm_initialize(int minor, FAR void **handle); * * Description: * Un-initialize the USB storage class driver. This function is used - * internally by the USB composite driver to uninitialized the CDC/ACM + * internally by the USB composite driver to uninitialize the CDC/ACM * driver. This same interface is available (with an untyped input * parameter) when the CDC/ACM driver is used standalone. *