All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Blue Swirl <blauwirbel@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Error check find_ram_offset
Date: Mon, 31 Oct 2011 16:42:15 +0100	[thread overview]
Message-ID: <m339e9182w.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <20111031145311.13723.63607.stgit@s20.home> (Alex Williamson's message of "Mon, 31 Oct 2011 08:54:09 -0600")

Alex Williamson <alex.williamson@redhat.com> writes:

> Spotted via code review, we initialize offset to 0 to avoid a
> compiler warning, but in the unlikely case that offset is
> never set to something else, we should abort instead of return
> a value that will almost certainly cause problems.

Compiler warning pointed to the problem until commit 09d7ae90 "Fix
warning about uninitialized variable" papered over it.

> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>
>  exec.c |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 9dc4edb..70f6fb8 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2874,7 +2874,7 @@ static void *file_ram_alloc(RAMBlock *block,
>  static ram_addr_t find_ram_offset(ram_addr_t size)
>  {
>      RAMBlock *block, *next_block;
> -    ram_addr_t offset = 0, mingap = RAM_ADDR_MAX;
> +    ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX;
>  
>      if (QLIST_EMPTY(&ram_list.blocks))
>          return 0;
> @@ -2890,10 +2890,17 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
>              }
>          }
>          if (next - end >= size && next - end < mingap) {
> -            offset =  end;
> +            offset = end;
>              mingap = next - end;
>          }
>      }
> +
> +    if (offset == RAM_ADDR_MAX) {
> +        fprintf(stderr, "Failed to find gap of requested size: %" PRIu64 "\n",
> +                (uint64_t)size);
> +        abort();
> +    }
> +
>      return offset;
>  }

The loop can't yield offset RAM_ADDR_MAX, because size needs to be zero
for next - end >= size to succeed, and that's not possible.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

  reply	other threads:[~2011-10-31 15:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 14:54 [Qemu-devel] [PATCH] Error check find_ram_offset Alex Williamson
2011-10-31 15:42 ` Markus Armbruster [this message]
2011-11-01 16:20 ` Anthony Liguori

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=m339e9182w.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=blauwirbel@gmail.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.