* [Qemu-devel] [PATCH] Error check find_ram_offset
@ 2011-10-31 14:54 Alex Williamson
2011-10-31 15:42 ` Markus Armbruster
2011-11-01 16:20 ` Anthony Liguori
0 siblings, 2 replies; 3+ messages in thread
From: Alex Williamson @ 2011-10-31 14:54 UTC (permalink / raw)
To: qemu-devel; +Cc: alex.williamson, armbru
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.
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;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Error check find_ram_offset
2011-10-31 14:54 [Qemu-devel] [PATCH] Error check find_ram_offset Alex Williamson
@ 2011-10-31 15:42 ` Markus Armbruster
2011-11-01 16:20 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2011-10-31 15:42 UTC (permalink / raw)
To: Alex Williamson; +Cc: Blue Swirl, qemu-devel
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Error check find_ram_offset
2011-10-31 14:54 [Qemu-devel] [PATCH] Error check find_ram_offset Alex Williamson
2011-10-31 15:42 ` Markus Armbruster
@ 2011-11-01 16:20 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2011-11-01 16:20 UTC (permalink / raw)
To: Alex Williamson; +Cc: qemu-devel, armbru
On 10/31/2011 09:54 AM, Alex Williamson wrote:
> 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.
>
> Signed-off-by: Alex Williamson<alex.williamson@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
>
> 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;
> }
>
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-01 16:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-31 14:54 [Qemu-devel] [PATCH] Error check find_ram_offset Alex Williamson
2011-10-31 15:42 ` Markus Armbruster
2011-11-01 16:20 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).