dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0231-Error-check-find_ram_offset.patch

cd9d16
From 75f2b558df8c3ccd8b980eedf2f4aef8b217587e Mon Sep 17 00:00:00 2001
cd9d16
From: Alex Williamson <alex.williamson@redhat.com>
cd9d16
Date: Mon, 31 Oct 2011 08:54:09 -0600
cd9d16
Subject: [PATCH] Error check find_ram_offset
cd9d16
MIME-Version: 1.0
cd9d16
Content-Type: text/plain; charset=UTF-8
cd9d16
Content-Transfer-Encoding: 8bit
cd9d16
cd9d16
Spotted via code review, we initialize offset to 0 to avoid a
cd9d16
compiler warning, but in the unlikely case that offset is
cd9d16
never set to something else, we should abort instead of return
cd9d16
a value that will almost certainly cause problems.
cd9d16
cd9d16
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
cd9d16
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
cd9d16
(cherry picked from commit 3e837b2c05bc63fe2226baf3c29923d5a688593f)
cd9d16
cd9d16
Signed-off-by: Bruce Rogers <brogers@suse.com>
cd9d16
Signed-off-by: Andreas Färber <afaerber@suse.de>
cd9d16
---
cd9d16
 exec.c | 11 +++++++++--
cd9d16
 1 file changed, 9 insertions(+), 2 deletions(-)
cd9d16
cd9d16
diff --git a/exec.c b/exec.c
cd9d16
index 6fb589b..537a49f 100644
cd9d16
--- a/exec.c
cd9d16
+++ b/exec.c
cd9d16
@@ -2863,7 +2863,7 @@ static void *file_ram_alloc(RAMBlock *block,
cd9d16
 static ram_addr_t find_ram_offset(ram_addr_t size)
cd9d16
 {
cd9d16
     RAMBlock *block, *next_block;
cd9d16
-    ram_addr_t offset = 0, mingap = RAM_ADDR_MAX;
cd9d16
+    ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX;
cd9d16
 
cd9d16
     if (QLIST_EMPTY(&ram_list.blocks))
cd9d16
         return 0;
cd9d16
@@ -2879,10 +2879,17 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
cd9d16
             }
cd9d16
         }
cd9d16
         if (next - end >= size && next - end < mingap) {
cd9d16
-            offset =  end;
cd9d16
+            offset = end;
cd9d16
             mingap = next - end;
cd9d16
         }
cd9d16
     }
cd9d16
+
cd9d16
+    if (offset == RAM_ADDR_MAX) {
cd9d16
+        fprintf(stderr, "Failed to find gap of requested size: %" PRIu64 "\n",
cd9d16
+                (uint64_t)size);
cd9d16
+        abort();
cd9d16
+    }
cd9d16
+
cd9d16
     return offset;
cd9d16
 }
cd9d16
 
cd9d16
-- 
cd9d16
1.7.11.2
cd9d16