diff mbox

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

Message ID 1458768411-6024-1-git-send-email-srn@prgmr.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sarah Newman March 23, 2016, 9: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.

Remove the break and re-add "some !=0" in the loop for HAVE_LIBC.

Signed-off-by: Sarah Newman <srn@prgmr.com>
---
 netfront.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Wei Liu March 25, 2016, 1:09 p.m. UTC | #1
CC Samuel

On Wed, Mar 23, 2016 at 02:26:51PM -0700, Sarah Newman 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.
> 
> Remove the break and re-add "some !=0" in the loop for HAVE_LIBC.
> 
> Signed-off-by: Sarah Newman <srn@prgmr.com>
> ---
>  netfront.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/netfront.c b/netfront.c
> index 0eca5b5..557e8c4 100644
> --- a/netfront.c
> +++ b/netfront.c
> @@ -108,8 +108,10 @@ moretodo:
>  
>  #ifdef HAVE_LIBC
>      some = 0;
> -#endif
> +    for (cons = dev->rx.rsp_cons; (cons != rp) && !some; nr_consumed++, cons++)
> +#else
>      for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++)
> +#endif
>      {
>          struct net_buffer* buf;
>          unsigned char* page;
> @@ -135,7 +137,6 @@ moretodo:
>  		memcpy(dev->data, page+rx->offset, len);
>  		dev->rlen = len;
>  		some = 1;
> -                break;
>  	    } else
>  #endif
>  		dev->netif_rx(page+rx->offset,rx->status);
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
diff mbox

Patch

diff --git a/netfront.c b/netfront.c
index 0eca5b5..557e8c4 100644
--- a/netfront.c
+++ b/netfront.c
@@ -108,8 +108,10 @@  moretodo:
 
 #ifdef HAVE_LIBC
     some = 0;
-#endif
+    for (cons = dev->rx.rsp_cons; (cons != rp) && !some; nr_consumed++, cons++)
+#else
     for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++)
+#endif
     {
         struct net_buffer* buf;
         unsigned char* page;
@@ -135,7 +137,6 @@  moretodo:
 		memcpy(dev->data, page+rx->offset, len);
 		dev->rlen = len;
 		some = 1;
-                break;
 	    } else
 #endif
 		dev->netif_rx(page+rx->offset,rx->status);