diff mbox

Mini-OS: netfront: fix off-by-one error introduced in 7c8f3483

Message ID 1459535176-13178-1-git-send-email-samuel.thibault@ens-lyon.org (mailing list archive)
State New, archived
Headers show

Commit Message

Samuel Thibault April 1, 2016, 6:26 p.m. UTC
7c8f3483 introduced a break within a loop in netfront.c such that
cons and nr_consumed were no longer always being incremented. The
offset at cons will be processed multiple times with the break in
place.

This commit reverts to using the "some" variable in the loop condition,
but avoids ifdefs for the non-libc case. It also renames it to dobreak
to make its usage clearer.

Suggested-by: Sarah Newman <srn@prgmr.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Tested-by: Sarah Newman <srn@prgmr.com>
---
 netfront.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

Comments

Wei Liu April 4, 2016, 10:28 a.m. UTC | #1
On Fri, Apr 01, 2016 at 08:26:16PM +0200, Samuel Thibault wrote:
> 7c8f3483 introduced a break within a loop in netfront.c such that
> cons and nr_consumed were no longer always being incremented. The
> offset at cons will be processed multiple times with the break in
> place.
> 
> This commit reverts to using the "some" variable in the loop condition,
> but avoids ifdefs for the non-libc case. It also renames it to dobreak
> to make its usage clearer.
> 
> Suggested-by: Sarah Newman <srn@prgmr.com>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Tested-by: Sarah Newman <srn@prgmr.com>

Queued. Thank you both!
Wei Liu April 25, 2016, 11:14 a.m. UTC | #2
On Mon, Apr 04, 2016 at 11:28:00AM +0100, Wei Liu wrote:
> On Fri, Apr 01, 2016 at 08:26:16PM +0200, Samuel Thibault wrote:
> > 7c8f3483 introduced a break within a loop in netfront.c such that
> > cons and nr_consumed were no longer always being incremented. The
> > offset at cons will be processed multiple times with the break in
> > place.
> > 
> > This commit reverts to using the "some" variable in the loop condition,
> > but avoids ifdefs for the non-libc case. It also renames it to dobreak
> > to make its usage clearer.
> > 
> > Suggested-by: Sarah Newman <srn@prgmr.com>
> > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > Tested-by: Sarah Newman <srn@prgmr.com>
> 
> Queued. Thank you both!

This is now backported to mini-os.git xen-stable-4.6 branch.
diff mbox

Patch

diff --git a/netfront.c b/netfront.c
index 0eca5b5..b8fac62 100644
--- a/netfront.c
+++ b/netfront.c
@@ -97,19 +97,15 @@  void network_rx(struct netfront_dev *dev)
 {
     RING_IDX rp,cons,req_prod;
     int nr_consumed, more, i, notify;
-#ifdef HAVE_LIBC
-    int some;
-#endif
+    int dobreak;
 
     nr_consumed = 0;
 moretodo:
     rp = dev->rx.sring->rsp_prod;
     rmb(); /* Ensure we see queued responses up to 'rp'. */
 
-#ifdef HAVE_LIBC
-    some = 0;
-#endif
-    for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++)
+    dobreak = 0;
+    for (cons = dev->rx.rsp_cons; cons != rp && !dobreak; nr_consumed++, cons++)
     {
         struct net_buffer* buf;
         unsigned char* page;
@@ -134,8 +130,8 @@  moretodo:
 		    len = dev->len;
 		memcpy(dev->data, page+rx->offset, len);
 		dev->rlen = len;
-		some = 1;
-                break;
+		/* No need to receive the rest for now */
+		dobreak = 1;
 	    } else
 #endif
 		dev->netif_rx(page+rx->offset,rx->status);
@@ -144,11 +140,7 @@  moretodo:
     dev->rx.rsp_cons=cons;
 
     RING_FINAL_CHECK_FOR_RESPONSES(&dev->rx,more);
-#ifdef HAVE_LIBC
-    if(more && !some) goto moretodo;
-#else
-    if(more) goto moretodo;
-#endif
+    if(more && !dobreak) goto moretodo;
 
     req_prod = dev->rx.req_prod_pvt;