diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-12 12:58:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-12 12:58:56 +0000 |
commit | 89b1a8ab25add376d10563320dc01c4843118596 (patch) | |
tree | 6635001e24e49d9944fe3db24265843737b450b9 | |
parent | 7596c8e003e4bbe8722cce117d283d6209257445 (diff) | |
download | nuttx-89b1a8ab25add376d10563320dc01c4843118596.tar.gz nuttx-89b1a8ab25add376d10563320dc01c4843118596.tar.bz2 nuttx-89b1a8ab25add376d10563320dc01c4843118596.zip |
Fix USB host error handling logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3593 42af7a65-404d-4744-a932-0658087f49c3
-rwxr-xr-x | nuttx/drivers/usbhost/usbhost_enumerate.c | 4 | ||||
-rw-r--r-- | nuttx/drivers/usbhost/usbhost_hidkbd.c | 4 | ||||
-rw-r--r-- | nuttx/drivers/usbhost/usbhost_skeleton.c | 12 | ||||
-rw-r--r-- | nuttx/drivers/usbhost/usbhost_storage.c | 12 | ||||
-rw-r--r-- | nuttx/include/nuttx/usb/usbhost.h | 4 |
5 files changed, 20 insertions, 16 deletions
diff --git a/nuttx/drivers/usbhost/usbhost_enumerate.c b/nuttx/drivers/usbhost/usbhost_enumerate.c index 1c3a827bf..8e1cd80e7 100755 --- a/nuttx/drivers/usbhost/usbhost_enumerate.c +++ b/nuttx/drivers/usbhost/usbhost_enumerate.c @@ -249,6 +249,10 @@ static inline int usbhost_classbind(FAR struct usbhost_driver_s *drvr, ret = CLASS_CONNECT(devclass, configdesc, desclen, funcaddr); if (ret != OK) { + /* On failures, call the class disconnect method which + * should then free the allocated devclass instance. + */ + udbg("CLASS_CONNECT failed: %d\n", ret); CLASS_DISCONNECTED(devclass); } diff --git a/nuttx/drivers/usbhost/usbhost_hidkbd.c b/nuttx/drivers/usbhost/usbhost_hidkbd.c index ef880ea75..baf18703d 100644 --- a/nuttx/drivers/usbhost/usbhost_hidkbd.c +++ b/nuttx/drivers/usbhost/usbhost_hidkbd.c @@ -1545,6 +1545,10 @@ static FAR struct usbhost_class_s *usbhost_create(FAR struct usbhost_driver_s *d * On success, zero (OK) is returned. On a failure, a negated errno value is * returned indicating the nature of the failure * + * NOTE that the class instance remains valid upon return with a failure. It is + * the responsibility of the higher level enumeration logic to call + * CLASS_DISCONNECTED to free up the class driver resources. + * * Assumptions: * - This function will *not* be called from an interrupt handler. * - If this function returns an error, the USB host controller driver diff --git a/nuttx/drivers/usbhost/usbhost_skeleton.c b/nuttx/drivers/usbhost/usbhost_skeleton.c index c33dda586..206b347c5 100644 --- a/nuttx/drivers/usbhost/usbhost_skeleton.c +++ b/nuttx/drivers/usbhost/usbhost_skeleton.c @@ -673,14 +673,6 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv) } } - /* Disconnect on any errors detected during volume initialization */ - - if (ret != OK) - { - udbg("ERROR! Aborting: %d\n", ret); - usbhost_destroy(priv); - } - return ret; } @@ -924,6 +916,10 @@ static FAR struct usbhost_class_s *usbhost_create(FAR struct usbhost_driver_s *d * On success, zero (OK) is returned. On a failure, a negated errno value is * returned indicating the nature of the failure * + * NOTE that the class instance remains valid upon return with a failure. It is + * the responsibility of the higher level enumeration logic to call + * CLASS_DISCONNECTED to free up the class driver resources. + * * Assumptions: * - This function will *not* be called from an interrupt handler. * - If this function returns an error, the USB host controller driver diff --git a/nuttx/drivers/usbhost/usbhost_storage.c b/nuttx/drivers/usbhost/usbhost_storage.c index 118758a60..7a41cde65 100644 --- a/nuttx/drivers/usbhost/usbhost_storage.c +++ b/nuttx/drivers/usbhost/usbhost_storage.c @@ -937,6 +937,10 @@ static void usbhost_destroy(FAR void *arg) * On success, zero (OK) is returned. On a failure, a negated errno value is * returned indicating the nature of the failure * + * NOTE that the class instance remains valid upon return with a failure. It is + * the responsibility of the higher level enumeration logic to call + * CLASS_DISCONNECTED to free up the class driver resources. + * * Assumptions: * This function will *not* be called from an interrupt handler. * @@ -1308,14 +1312,6 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv) } } - /* Disconnect on any errors detected during volume initialization */ - - if (ret != OK) - { - udbg("ERROR! Aborting: %d\n", ret); - usbhost_destroy(priv); - } - return ret; } diff --git a/nuttx/include/nuttx/usb/usbhost.h b/nuttx/include/nuttx/usb/usbhost.h index 25eda9c79..7f1bd880e 100644 --- a/nuttx/include/nuttx/usb/usbhost.h +++ b/nuttx/include/nuttx/usb/usbhost.h @@ -113,6 +113,10 @@ * On success, zero (OK) is returned. On a failure, a negated errno value is * returned indicating the nature of the failure * + * NOTE that the class instance remains valid upon return with a failure. It is + * the responsibility of the higher level enumeration logic to call + * CLASS_DISCONNECTED to free up the class driver resources. + * * Assumptions: * - This function is probably called on the same thread that called the driver * enumerate() method. This function will *not* be called from an interrupt |