qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org, Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] [PULL 4/8] arm/boot: Free dtb blob memory after use
Date: Tue, 25 Jun 2013 19:21:52 +0100	[thread overview]
Message-ID: <1372184516-32397-5-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1372184516-32397-1-git-send-email-peter.maydell@linaro.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 <peter.maydell@linaro.org>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Message-id: 1371209256-11408-1-git-send-email-peter.maydell@linaro.org
---
 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 797c691..7c0090f 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -237,14 +237,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);
 
@@ -252,7 +252,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;
@@ -264,7 +264,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);
@@ -273,13 +273,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) {
@@ -287,6 +288,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;
         }
     }
 
@@ -295,19 +297,27 @@ 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;
 }
 
 static void do_cpu_reset(void *opaque)
-- 
1.7.9.5

  parent reply	other threads:[~2013-06-25 18:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-25 18:21 [Qemu-devel] [PULL 0/8] arm-devs queue Peter Maydell
2013-06-25 18:21 ` [Qemu-devel] [PULL 1/8] ARM: Allow dumping of device tree Peter Maydell
2013-06-25 18:21 ` [Qemu-devel] [PULL 2/8] i.MX: Implement a more complete version of the GPT timer Peter Maydell
2013-06-25 18:42   ` Paolo Bonzini
2013-06-25 20:53     ` Peter Maydell
2013-06-26  6:56       ` Paolo Bonzini
2013-06-26  7:08         ` jcd
2013-06-26  7:11           ` Paolo Bonzini
2013-06-26  7:17             ` jcd
2013-06-26  7:21         ` Peter Crosthwaite
2013-06-26 18:58           ` Jean-Christophe DUBOIS
2013-06-26 21:13             ` Jean-Christophe DUBOIS
2013-06-26 21:18               ` Paolo Bonzini
2013-06-26 21:57                 ` Jean-Christophe DUBOIS
2013-06-26 22:15                   ` Peter Maydell
2013-06-26 22:32                     ` Jean-Christophe DUBOIS
2013-06-27 10:46                       ` Peter Maydell
2013-06-26 22:17                   ` Andreas Färber
2013-06-25 18:21 ` [Qemu-devel] [PULL 3/8] i.MX: Rework functions/types name and use new style initialization Peter Maydell
2013-06-25 18:21 ` Peter Maydell [this message]
2013-06-25 18:21 ` [Qemu-devel] [PULL 5/8] i.MX31: Fix PRCS bit test Peter Maydell
2013-06-25 18:21 ` [Qemu-devel] [PULL 6/8] block/nand: QOM casting sweep Peter Maydell
2013-06-25 18:21 ` [Qemu-devel] [PULL 7/8] block/nand: Convert Sysbus::init to Device::realize Peter Maydell
2013-06-25 18:21 ` [Qemu-devel] [PULL 8/8] nand: Don't inherit from Sysbus Peter Maydell
2013-06-25 19:07 ` [Qemu-devel] [PULL 0/8] arm-devs queue Anthony Liguori
2013-06-25 20:49   ` Peter Maydell
2013-06-25 21:45     ` Anthony Liguori
2013-06-25 22:01       ` Peter Maydell

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=1372184516-32397-5-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=aliguori@us.ibm.com \
    --cc=paul@codesourcery.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 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).