USB host: More fixes from last changes.. MSC block read and write must again return number of blocks on success. Fix numerous places where the assumption the ret == OK means success. Since the transfer method now returns the number of byte transfered, the correct test for success is ret >= 0

This commit is contained in:
Gregory Nutt 2015-05-05 15:48:48 -06:00
parent 3474a5536b
commit 4a8fbd8817
2 changed files with 28 additions and 26 deletions

View File

@ -585,14 +585,14 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
/* We are good... Allocate the endpoints */
ret = DRVR_EPALLOC(hport->drvr, &boutdesc, &priv->epout);
if (ret != OK)
if (ret < 0)
{
udbg("ERROR: Failed to allocate Bulk OUT endpoint\n");
return ret;
}
ret = DRVR_EPALLOC(hport->drvr, &bindesc, &priv->epin);
if (ret != OK)
if (ret < 0)
{
udbg("ERROR: Failed to allocate Bulk IN endpoint\n");
(void)DRVR_EPFREE(hport->drvr, priv->epout);
@ -639,7 +639,7 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv)
/* Register the driver */
if (ret == OK)
if (ret >= 0)
{
char devname[DEV_NAMELEN];
@ -653,7 +653,7 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv)
* driver has been registerd.
*/
if (ret == OK)
if (ret >= 0)
{
usbhost_takesem(&priv->exclsem);
DEBUGASSERT(priv->crefs >= 2);
@ -952,7 +952,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
/* Parse the configuration descriptor to get the endpoints */
ret = usbhost_cfgdesc(priv, configdesc, desclen);
if (ret != OK)
if (ret < 0)
{
udbg("usbhost_cfgdesc() failed: %d\n", ret);
}
@ -961,7 +961,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
/* Now configure the device and register the NuttX driver */
ret = usbhost_devinit(priv);
if (ret != OK)
if (ret < 0)
{
udbg("usbhost_devinit() failed: %d\n", ret);
}

View File

@ -695,7 +695,7 @@ static inline int usbhost_maxlunreq(FAR struct usbhost_state_s *priv)
hport = priv->usbclass.hport;
ret = DRVR_CTRLIN(hport->drvr, hport->ep0, req, priv->tbuffer);
if (ret != OK)
if (ret < 0)
{
/* Devices that do not support multiple LUNs may stall this command.
* On a failure, a single LUN is assumed.
@ -1170,14 +1170,14 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
/* We are good... Allocate the endpoints */
ret = DRVR_EPALLOC(hport->drvr, &boutdesc, &priv->bulkout);
if (ret != OK)
if (ret < 0)
{
udbg("ERROR: Failed to allocate Bulk OUT endpoint\n");
return ret;
}
ret = DRVR_EPALLOC(hport->drvr, &bindesc, &priv->bulkin);
if (ret != OK)
if (ret < 0)
{
udbg("ERROR: Failed to allocate Bulk IN endpoint\n");
(void)DRVR_EPFREE(hport->drvr, priv->bulkout);
@ -1218,7 +1218,7 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
/* Set aside a transfer buffer for exclusive use by the mass storage driver */
ret = usbhost_talloc(priv);
if (ret != OK)
if (ret < 0)
{
udbg("ERROR: Failed to allocate transfer buffer\n");
return ret;
@ -1236,7 +1236,7 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
uvdbg("Get max LUN\n");
ret = usbhost_maxlunreq(priv);
for (retries = 0; retries < USBHOST_MAX_RETRIES /* && ret == OK */; retries++)
for (retries = 0; retries < USBHOST_MAX_RETRIES /* && ret >= 0 */; retries++)
{
uvdbg("Test unit ready, retries=%d\n", retries);
@ -1250,7 +1250,7 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
*/
ret = usbhost_testunitready(priv);
if (ret == OK)
if (ret >= 0)
{
/* Is the unit is ready */
@ -1293,13 +1293,13 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
ret = -ETIMEDOUT;
}
if (ret == OK)
if (ret >= 0)
{
/* Get the capacity of the volume */
uvdbg("Read capacity\n");
ret = usbhost_readcapacity(priv);
if (ret == OK)
if (ret >= 0)
{
/* Check the CSW for errors */
@ -1314,13 +1314,13 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
/* Get information about the volume */
if (ret == OK)
if (ret >= 0)
{
/* Inquiry */
uvdbg("Inquiry\n");
ret = usbhost_inquiry(priv);
if (ret == OK)
if (ret >= 0)
{
/* Check the CSW for errors */
@ -1335,7 +1335,7 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
/* Register the block driver */
if (ret == OK)
if (ret >= 0)
{
char devname[DEV_NAMELEN];
@ -1364,7 +1364,7 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv)
* is called.
*/
if (ret == OK && priv->crefs <= 1 && priv->disconnected)
if (ret >= 0 && priv->crefs <= 1 && priv->disconnected)
{
/* The will cause the enumeration logic to disconnect the class
* driver.
@ -1769,7 +1769,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
/* Parse the configuration descriptor to get the bulk I/O endpoints */
ret = usbhost_cfgdesc(priv, configdesc, desclen);
if (ret != OK)
if (ret < 0)
{
udbg("usbhost_cfgdesc() failed: %d\n", ret);
}
@ -1778,7 +1778,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
/* Now configure the LUNs and register the block driver(s) */
ret = usbhost_initvolume(priv);
if (ret != OK)
if (ret < 0)
{
udbg("usbhost_initvolume() failed: %d\n", ret);
}
@ -2048,9 +2048,10 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer,
/* Check the CSW status */
csw = (FAR struct usbmsc_csw_s *)priv->tbuffer;
if (csw->status == 0)
if (csw->status != 0)
{
nbytes = nsectors;
udbg("ERROR: CSW status error: %d\n", csw->status);
nbytes = -ENODEV;
}
}
}
@ -2063,7 +2064,7 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer,
/* On success, return the number of blocks read */
return nbytes < 0 ? (int)nbytes : OK;
return nbytes < 0 ? (int)nbytes : nsectors;
}
/****************************************************************************
@ -2145,9 +2146,10 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe
/* Check the CSW status */
csw = (FAR struct usbmsc_csw_s *)priv->tbuffer;
if (csw->status == 0)
if (csw->status != 0)
{
nbytes = nsectors;
udbg("ERROR: CSW status error: %d\n", csw->status);
nbytes = -ENODEV;
}
}
}
@ -2159,7 +2161,7 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe
/* On success, return the number of blocks written */
return nbytes < 0 ? (int)nbytes : OK;
return nbytes < 0 ? (int)nbytes : nsectors;
}
#endif