From patchwork Fri Apr 1 18:26:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8727011 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6DD2A9F39A for ; Fri, 1 Apr 2016 18:29:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 965D2203A1 for ; Fri, 1 Apr 2016 18:29:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3684202B8 for ; Fri, 1 Apr 2016 18:29:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am3m2-0005mj-5i; Fri, 01 Apr 2016 18:26:22 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am3m1-0005mW-HC for xen-devel@lists.xen.org; Fri, 01 Apr 2016 18:26:21 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 73/1C-04060-C4DBEF65; Fri, 01 Apr 2016 18:26:20 +0000 X-Env-Sender: SRS0=t/Ew=P4=ens-lyon.org=samuel.thibault@bounce.ens-lyon.o rg X-Msg-Ref: server-16.tower-31.messagelabs.com!1459535179!25084864!1 X-Originating-IP: [140.77.166.138] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3006 invoked from network); 1 Apr 2016 18:26:19 -0000 Received: from domu-toccata.ens-lyon.fr (HELO sonata.ens-lyon.org) (140.77.166.138) by server-16.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Apr 2016 18:26:19 -0000 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 88A582014B; Fri, 1 Apr 2016 20:26:19 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U2d8OvH4k0I0; Fri, 1 Apr 2016 20:26:19 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (LFbn-1-6757-94.w90-120.abo.wanadoo.fr [90.120.189.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 299C82014A; Fri, 1 Apr 2016 20:26:18 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1am3ly-0003RD-C6; Fri, 01 Apr 2016 20:26:18 +0200 From: Samuel Thibault To: xen-devel@lists.xen.org, minios-devel@lists.xenproject.org Date: Fri, 1 Apr 2016 20:26:16 +0200 Message-Id: <1459535176-13178-1-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 Cc: Samuel Thibault , wei.liu2@citrix.com, srn@prgmr.com Subject: [Xen-devel] [PATCH] Mini-OS: netfront: fix off-by-one error introduced in 7c8f3483 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Samuel Thibault Tested-by: Sarah Newman --- netfront.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) 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;