From patchwork Fri Jun 14 11:27:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 251377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1DF8A2C0084 for ; Fri, 14 Jun 2013 21:28:08 +1000 (EST) Received: from localhost ([::1]:57421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnSAm-0006I9-IQ for incoming@patchwork.ozlabs.org; Fri, 14 Jun 2013 07:28:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnSAU-00066T-JA for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:27:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UnSAR-0000r4-VX for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:27:46 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:57967 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnSAR-0000qE-OT for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:27:43 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1UnSAK-0002yT-CH; Fri, 14 Jun 2013 12:27:36 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 14 Jun 2013 12:27:36 +0100 Message-Id: <1371209256-11408-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: patches@linaro.org Subject: [Qemu-devel] [PATCH] arm/boot: Free dtb blob memory after use X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The dtb blob returned by load_device_tree() is in memory allocated with g_malloc(). Free it accordingly once we have copied its contents into the guest memory. To make this easy, we need also to clean up the error handling in load_dtb() so that we consistently handle errors in the same way (by printing a message and then returning -1, rather than either plowing on or exiting immediately). Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber --- hw/arm/boot.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index f8c2031..f5870f6 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -238,14 +238,14 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename); if (!filename) { fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename); - return -1; + goto fail; } fdt = load_device_tree(filename, &size); if (!fdt) { fprintf(stderr, "Couldn't open dtb file %s\n", filename); g_free(filename); - return -1; + goto fail; } g_free(filename); @@ -253,7 +253,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells"); if (acells == 0 || scells == 0) { fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n"); - return -1; + goto fail; } mem_reg_propsize = acells + scells; @@ -265,7 +265,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) } else if (hival != 0) { fprintf(stderr, "qemu: dtb file not compatible with " "RAM start address > 4GB\n"); - exit(1); + goto fail; } mem_reg_property[acells + scells - 1] = cpu_to_be32(binfo->ram_size); hival = cpu_to_be32(binfo->ram_size >> 32); @@ -274,13 +274,14 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) } else if (hival != 0) { fprintf(stderr, "qemu: dtb file not compatible with " "RAM size > 4GB\n"); - exit(1); + goto fail; } rc = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, mem_reg_propsize * sizeof(uint32_t)); if (rc < 0) { fprintf(stderr, "couldn't set /memory/reg\n"); + goto fail; } if (binfo->kernel_cmdline && *binfo->kernel_cmdline) { @@ -288,6 +289,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) binfo->kernel_cmdline); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/bootargs\n"); + goto fail; } } @@ -296,20 +298,28 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) binfo->initrd_start); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); + goto fail; } rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", binfo->initrd_start + binfo->initrd_size); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); + goto fail; } } qemu_devtree_dumpdtb(fdt, size); cpu_physical_memory_write(addr, fdt, size); + g_free(fdt); + return 0; +fail: + g_free(fdt); + return -1; + #else fprintf(stderr, "Device tree requested, " "but qemu was compiled without fdt support\n");