From 05f8581874897aecd8f24c1e17c62f8e0e027cd9 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Mon, 27 Oct 2008 22:45:55 +0000
Subject: [PATCH] Fix read failures when OUT req size > maxpacket

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1086 42af7a65-404d-4744-a932-0658087f49c3
---
 ChangeLog                             |  2 ++
 Documentation/NuttX.html              |  2 ++
 arch/arm/src/dm320/dm320_usbdev.c     | 41 ++++++++++++---------------
 arch/arm/src/lpc214x/lpc214x_usbdev.c | 41 ++++++++++++---------------
 4 files changed, 40 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d56d12d02a..accf731ee5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -518,6 +518,8 @@
 	  to terminate an IN transfer with a short packet (zero-length if necessary).
 	* Fix an error in the NXP LPC214x USB device driver that was causing corruption of
 	  the request queue (M320 driver also fixed, untested)
+	* Correct another error in the NXP LPC214x USB device driver that caused read failures
+	  when the request buffer size was larger than maxpacket.
 
 
 
diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html
index cf95485381..a93e24cff9 100644
--- a/Documentation/NuttX.html
+++ b/Documentation/NuttX.html
@@ -1148,6 +1148,8 @@ nuttx-0.3.17 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
 	  to terminate an IN transfer with a short packet (zero-length if necessary).
 	* Fix an error in the NXP LPC214x USB device driver that was causing corruption of
 	  the request queue (M320 driver also fixed, untested)
+	* Correct another error in the NXP LPC214x USB device driver that caused read failures
+	  when the request buffer size was larger than maxpacket.
 
 pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
 
diff --git a/arch/arm/src/dm320/dm320_usbdev.c b/arch/arm/src/dm320/dm320_usbdev.c
index c585c3fe97..0076f0067b 100644
--- a/arch/arm/src/dm320/dm320_usbdev.c
+++ b/arch/arm/src/dm320/dm320_usbdev.c
@@ -1039,34 +1039,29 @@ static int dm320_rdrequest(struct dm320_ep_s *privep)
     }
 
   usbtrace(TRACE_READ(privep->epphy), privreq->req.xfrd);
-  for (;;)
-    {
-      /* Receive the next packet if (1) there are more bytes to be receive, or
-       * (2) the last packet was exactly maxpacketsize.
-       */
 
-      buf        = privreq->req.buf + privreq->req.xfrd;
-      nbytesread = dm320_epread(privep->epphy, buf, privep->ep.maxpacket);
-      if (nbytesread < 0)
-        {
-          usbtrace(TRACE_DEVERROR(DM320_TRACEERR_EPREAD), nbytesread);
-          return ERROR;
-        }
+  /* Receive the next packet */
 
-      /* If the receive buffer is full or if the last packet was not full
-       * then we are finished with the transfer.
-       */
+  buf        = privreq->req.buf + privreq->req.xfrd;
+  nbytesread = dm320_epread(privep->epphy, buf, privep->ep.maxpacket);
+  if (nbytesread < 0)
+    {
+      usbtrace(TRACE_DEVERROR(DM320_TRACEERR_EPREAD), nbytesread);
+      return ERROR;
+    }
 
-      privreq->req.xfrd += nbytesread;
-      if (privreq->req.len < privreq->req.xfrd || nbytesread < privep->ep.maxpacket)
-        {
-          usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
-          dm320_reqcomplete(privep, OK);
-          return OK;
-        }
+  /* If the receive buffer is full or if the last packet was not full
+   * then we are finished with the transfer.
+   */
+
+  privreq->req.xfrd += nbytesread;
+  if (privreq->req.len < privreq->req.xfrd || nbytesread < privep->ep.maxpacket)
+    {
+      usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
+      dm320_reqcomplete(privep, OK);
     }
 
-  return OK; /* Won't get here */
+  return OK;
 }
 
 /*******************************************************************************
diff --git a/arch/arm/src/lpc214x/lpc214x_usbdev.c b/arch/arm/src/lpc214x/lpc214x_usbdev.c
index 71c30596d2..e23da86cca 100644
--- a/arch/arm/src/lpc214x/lpc214x_usbdev.c
+++ b/arch/arm/src/lpc214x/lpc214x_usbdev.c
@@ -1136,34 +1136,29 @@ static int lpc214x_rdrequest(struct lpc214x_ep_s *privep)
     }
 
   usbtrace(TRACE_READ(privep->epphy), privreq->req.xfrd);
-  for (;;)
-    {
-      /* Receive the next packet if (1) there are more bytes to be receive, or
-       * (2) the last packet was exactly maxpacketsize.
-       */
 
-      buf        = privreq->req.buf + privreq->req.xfrd;
-      nbytesread = lpc214x_epread(privep->epphy, buf, privep->ep.maxpacket);
-      if (nbytesread < 0)
-        {
-          usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_EPREAD), nbytesread);
-          return ERROR;
-        }
+  /* Receive the next packet */
 
-      /* If the receive buffer is full or if the last packet was not full
-       * then we are finished with the transfer.
-       */
+  buf        = privreq->req.buf + privreq->req.xfrd;
+  nbytesread = lpc214x_epread(privep->epphy, buf, privep->ep.maxpacket);
+  if (nbytesread < 0)
+    {
+      usbtrace(TRACE_DEVERROR(LPC214X_TRACEERR_EPREAD), nbytesread);
+      return ERROR;
+    }
 
-      privreq->req.xfrd += nbytesread;
-      if (privreq->req.xfrd >= privreq->req.len || nbytesread < privep->ep.maxpacket)
-        {
-          usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
-          lpc214x_reqcomplete(privep, OK);
-          return OK;
-        }
+  /* If the receive buffer is full or if the last packet was not full
+   * then we are finished with the transfer.
+   */
+
+  privreq->req.xfrd += nbytesread;
+  if (privreq->req.xfrd >= privreq->req.len || nbytesread < privep->ep.maxpacket)
+    {
+      usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
+      lpc214x_reqcomplete(privep, OK);
     }
 
-  return OK; /* Won't get here */
+  return OK;
 }
 
 /*******************************************************************************
-- 
GitLab