summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-26 17:27:57 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-26 17:27:57 +0000
commit6d81a3c8f554607158cb603cdd67f3bf195a1462 (patch)
tree76df8f8506df34e33ab588ab888dfe5616c81caf
parent953adf8554a3f1629a781569659ebf10348e42d1 (diff)
downloadnuttx-6d81a3c8f554607158cb603cdd67f3bf195a1462.tar.gz
nuttx-6d81a3c8f554607158cb603cdd67f3bf195a1462.tar.bz2
nuttx-6d81a3c8f554607158cb603cdd67f3bf195a1462.zip
Correct USB mass storage memory leak
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3820 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/ChangeLog9
-rw-r--r--nuttx/TODO25
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_usbdev.c11
-rw-r--r--nuttx/drivers/usbdev/usbdev_storage.c17
4 files changed, 27 insertions, 35 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 396f3ae88..3cafb1610 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -1944,4 +1944,11 @@
Distribution Format (BDF) into fonts that can be used in the NX graphics
system.
* include/nuttx/nx: Move all NX header files from include/nuttx to
- include/nuttx/nx. \ No newline at end of file
+ include/nuttx/nx.
+ * drivers/usbdev/usbdev_usbstorage.c and arch/arm/src/stm32/stm32_usbdev.c:
+ Correct a memory leak when the USB mass storage driver is connected and
+ then disconnected from the target. The write requests were not being
+ freed. NOTE that the unregister logic in the STM32 needed to call
+ stm32_reset() in order to return the write requests to the USB mass
+ storage driver; it is possible that a similar but could exist for other
+ architectures.
diff --git a/nuttx/TODO b/nuttx/TODO
index f9fc8614a..d4f34a1df 100644
--- a/nuttx/TODO
+++ b/nuttx/TODO
@@ -42,7 +42,7 @@ apps/
(5) Network Utilities (apps/netutils/)
(5) NuttShell (NSH) (apps/nshlib)
- (6) Other Applications & Tests (apps/examples/)
+ (5) Other Applications & Tests (apps/examples/)
o Task/Scheduler (sched/)
^^^^^^^^^^^^^^^^^^^^^^^
@@ -1318,26 +1318,3 @@ o Other Applications & Tests (apps/examples/)
the artifact is larger.
Status: Open
Priority: Medium.
-
- Description: USB Mass Storage Memory Leak. When examples/usbstorage is
- built as an NuttShell (NSH) built-in, there appears to be a
- memory leak that occurs when a USB mass storage connection is
- established and then torn down. This leak is 608 bytes each
- time:
-
- NuttShell (NSH) NuttX-6.6
- nsh> free
- total used free largest
- Mem: 59360 9536 49824 49824
- nsh> msconn
- total used free largest
- Mem: 59360 15296 44064 41712
- nsh> msdis
- nsh> free
- total used free largest
- Mem: 59360 10144 49216 41712 <-- Leaked 608 bytes
- Status: Open
- Priority: Medium. Obviously, this must be fixed. However the USB
- Mass storage example is fine for supporting most development
- needs even thought it does leak.
-
diff --git a/nuttx/arch/arm/src/stm32/stm32_usbdev.c b/nuttx/arch/arm/src/stm32/stm32_usbdev.c
index 3fe54ea17..c1d6da803 100644
--- a/nuttx/arch/arm/src/stm32/stm32_usbdev.c
+++ b/nuttx/arch/arm/src/stm32/stm32_usbdev.c
@@ -3622,9 +3622,15 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
}
#endif
- /* Unbind the class driver */
+ /* Reset the hardware and cancel all requests. All requests must be
+ * canceled while the class driver is still bound.
+ */
flags = irqsave();
+ stm32_reset(priv);
+
+ /* Unbind the class driver */
+
CLASS_UNBIND(driver, &priv->usbdev);
/* Disable USB controller interrupts (but keep them attached) */
@@ -3633,7 +3639,8 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
up_disable_irq(STM32_IRQ_USBLPCANRX0);
/* Put the hardware in an inactive state. Then bring the hardware back up
- * in the reset state.
+ * in the reset state (this is probably not necessary, the stm32_reset()
+ * call above was probably sufficient).
*/
stm32_hwshutdown(priv);
diff --git a/nuttx/drivers/usbdev/usbdev_storage.c b/nuttx/drivers/usbdev/usbdev_storage.c
index 4f2ffcc6e..029cd748e 100644
--- a/nuttx/drivers/usbdev/usbdev_storage.c
+++ b/nuttx/drivers/usbdev/usbdev_storage.c
@@ -670,14 +670,6 @@ static void usbstrg_unbind(FAR struct usbdev_s *dev)
usbstrg_resetconfig(priv);
up_mdelay(50);
- /* Free the bulk IN endpoint */
-
- if (priv->epbulkin)
- {
- DEV_FREEEP(dev, priv->epbulkin);
- priv->epbulkin = NULL;
- }
-
/* Free the pre-allocated control request */
if (priv->ctrlreq != NULL)
@@ -721,6 +713,15 @@ static void usbstrg_unbind(FAR struct usbdev_s *dev)
usbstrg_freereq(priv->epbulkin, reqcontainer->req);
}
}
+
+ /* Free the bulk IN endpoint */
+
+ if (priv->epbulkin)
+ {
+ DEV_FREEEP(dev, priv->epbulkin);
+ priv->epbulkin = NULL;
+ }
+
irqrestore(flags);
}
}