From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCsN2-0005bq-KQ for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:53:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCsMs-0007wS-9z for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:53:00 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 28 Mar 2012 14:52:35 +0200 Message-Id: <1332939159-16434-33-git-send-email-afaerber@suse.de> In-Reply-To: <1332939159-16434-1-git-send-email-afaerber@suse.de> References: <1332939159-16434-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH stable-0.15 32/36] Error check find_ram_offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , kvm@suse.de, qemu-stable@nongnu.org, Bruce Rogers , Alex Williamson , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Alex Williamson 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 Signed-off-by: Anthony Liguori (cherry picked from commit 3e837b2c05bc63fe2226baf3c29923d5a688593f) Signed-off-by: Bruce Rogers Signed-off-by: Andreas F=C3=A4rber --- exec.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 6fb589b..537a49f 100644 --- a/exec.c +++ b/exec.c @@ -2863,7 +2863,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 =3D 0, mingap =3D RAM_ADDR_MAX; + ram_addr_t offset =3D RAM_ADDR_MAX, mingap =3D RAM_ADDR_MAX; =20 if (QLIST_EMPTY(&ram_list.blocks)) return 0; @@ -2879,10 +2879,17 @@ static ram_addr_t find_ram_offset(ram_addr_t size= ) } } if (next - end >=3D size && next - end < mingap) { - offset =3D end; + offset =3D end; mingap =3D next - end; } } + + if (offset =3D=3D RAM_ADDR_MAX) { + fprintf(stderr, "Failed to find gap of requested size: %" PRIu64= "\n", + (uint64_t)size); + abort(); + } + return offset; } =20 --=20 1.7.7