From patchwork Tue Sep 14 11:52:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 64693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9F78CB6F10 for ; Tue, 14 Sep 2010 21:59:06 +1000 (EST) Received: from localhost ([127.0.0.1]:52513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OvUAA-0007q8-G8 for incoming@patchwork.ozlabs.org; Tue, 14 Sep 2010 07:59:02 -0400 Received: from [140.186.70.92] (port=55266 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OvU9a-0007pG-1k for qemu-devel@nongnu.org; Tue, 14 Sep 2010 07:58:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OvU9Y-0006KT-SK for qemu-devel@nongnu.org; Tue, 14 Sep 2010 07:58:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59197) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OvU9Y-0006KK-LM for qemu-devel@nongnu.org; Tue, 14 Sep 2010 07:58:24 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8EBwNgE001043 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Sep 2010 07:58:23 -0400 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o8EBwJEa028251; Tue, 14 Sep 2010 07:58:19 -0400 Date: Tue, 14 Sep 2010 13:52:22 +0200 From: "Michael S. Tsirkin" To: Jes.Sorensen@redhat.com Message-ID: <20100914115222.GA703@redhat.com> References: <1284458772-6474-1-git-send-email-Jes.Sorensen@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1284458772-6474-1-git-send-email-Jes.Sorensen@redhat.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Alex.Williamson@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH 1/1] Fix loop logic in vhost_net_start()'s error path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, Sep 14, 2010 at 12:06:12PM +0200, Jes.Sorensen@redhat.com wrote: > From: Jes Sorensen > > file.index is unsigned, hence 'while (--file.index >= 0)' will loop > forever. Change it to do {} while (file.index-- > 0) > > Signed-off-by: Jes Sorensen > --- > hw/vhost_net.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/hw/vhost_net.c b/hw/vhost_net.c > index 4a7b819..b1f8072 100644 > --- a/hw/vhost_net.c > +++ b/hw/vhost_net.c > @@ -151,10 +151,10 @@ int vhost_net_start(struct vhost_net *net, > return 0; > fail: > file.fd = -1; > - while (--file.index >= 0) { > + do { > int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); > assert(r >= 0); > - } > + } while (file.index-- > 0); > net->vc->info->poll(net->vc, true); > vhost_dev_stop(&net->dev, dev); > if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { Hmm, this is not exactly right in that we first try with file.index and not file.index - 1; if SET_BACKEND originally failed with file.index and we try to undo this, we are likely to fail again and trigger an assert. I fixed this as follows. Thanks! vhost: fix infinite loop on error path file.index is unsigned, hence 'while (--file.index >= 0)' will loop > forever. Change to while (file.index-- > 0). Reported-by: Jes Sorensen Signed-off-by: Michael S. Tsirkin diff --git a/hw/vhost_net.c b/hw/vhost_net.c index 606aa0c..f2f4740 100644 --- a/hw/vhost_net.c +++ b/hw/vhost_net.c @@ -139,7 +139,7 @@ int vhost_net_start(struct vhost_net *net, return 0; fail: file.fd = -1; - while (--file.index >= 0) { + while (file.index-- > 0) { int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); assert(r >= 0); }