[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/56] arm/boot: Free dtb blob memory after use
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 02/56] arm/boot: Free dtb blob memory after use |
Date: |
Tue, 13 Aug 2013 10:10:26 -0500 |
From: Peter Maydell <address@hidden>
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 <address@hidden>
Reviewed-by: Andreas Färber <address@hidden>
Message-id: address@hidden
(cherry picked from commit c23045ded7571f0eaad95920ab00b6bc9c3a91e6)
Conflicts:
hw/arm/boot.c
* updated to include #ifdef for CONFIG_FDT
Signed-off-by: Michael Roth <address@hidden>
---
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 f451529..6bffc3d 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,19 +298,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;
}
}
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");
--
1.7.9.5
- [Qemu-devel] Patch Round-up for stable 1.5.3, freeze on 2013-08-16, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 02/56] arm/boot: Free dtb blob memory after use,
Michael Roth <=
- [Qemu-devel] [PATCH 03/56] ppc: do not register IABR SPR twice for 603e, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 01/56] s390/virtio-ccw: Fix virtio reset, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 04/56] qxl: Fix QXLRam initialisation., Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 05/56] virtio-scsi: forward scsibus for virtio-scsi-pci., Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 06/56] acl: acl_add can't insert before last list element, fix, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 07/56] usb-host-libusb: set USB_DEV_FLAG_IS_HOST, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 08/56] s390/ipl: Fix boot order, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 09/56] Fix iSCSI crash on SG_IO with an iovector, Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 10/56] block/ssh: Set bdrv_has_zero_init according to the file type., Michael Roth, 2013/08/13
- [Qemu-devel] [PATCH 13/56] Revert "migration: do not sent zero pages in bulk stage", Michael Roth, 2013/08/13