All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jes.Sorensen@redhat.com
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
Date: Tue, 14 Sep 2010 13:52:22 +0200	[thread overview]
Message-ID: <20100914115222.GA703@redhat.com> (raw)
In-Reply-To: <1284458772-6474-1-git-send-email-Jes.Sorensen@redhat.com>

On Tue, Sep 14, 2010 at 12:06:12PM +0200, Jes.Sorensen@redhat.com wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> 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 <Jes.Sorensen@redhat.com>
> ---
>  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 <Jes.Sorensen@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

--

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);
     }

      reply	other threads:[~2010-09-14 11:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 10:06 [Qemu-devel] [PATCH 1/1] Fix loop logic in vhost_net_start()'s error path Jes.Sorensen
2010-09-14 11:52 ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100914115222.GA703@redhat.com \
    --to=mst@redhat.com \
    --cc=Alex.Williamson@redhat.com \
    --cc=Jes.Sorensen@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.