diff mbox

[v5,3/6] hw/arm/boot: do not free VirtBoardInfo fdt in arm_load_dtb

Message ID 1417371570-11789-4-git-send-email-eric.auger@linaro.org
State New
Headers show

Commit Message

Auger Eric Nov. 30, 2014, 6:19 p.m. UTC
Currently arm_load_dtb frees the fdt handle whatever it is allocated
from load_device_tree or allocated externally.

When adding dynamic sysbus nodes after the first dtb load, we would like
to reuse the fdt used during the first load instead of re-creating the
whole device tree. If the fdt is destroyed, this is not possible.

Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
 hw/arm/boot.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Peter Maydell Dec. 5, 2014, 4:33 p.m. UTC | #1
On 30 November 2014 at 18:19, Eric Auger <eric.auger@linaro.org> wrote:
> Currently arm_load_dtb frees the fdt handle whatever it is allocated
> from load_device_tree or allocated externally.
>
> When adding dynamic sysbus nodes after the first dtb load, we would like
> to reuse the fdt used during the first load instead of re-creating the
> whole device tree. If the fdt is destroyed, this is not possible.
>
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> ---
>  hw/arm/boot.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index 0398cd4..0f9cd2c 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -427,12 +427,16 @@ int arm_load_dtb(const struct arm_boot_info *binfo)
>       */
>      rom_add_blob_fixed("dtb", fdt, size, binfo->dtb_start);
>
> -    g_free(fdt);
> +    if (binfo->dtb_filename) {
> +        g_free(fdt);
> +    }

This doesn't look right to me -- as you can see in this
hunk, we've already added the fdt as a ROM blob, so it's
complete and won't change hereafter. So there's nothing
further useful to do with the malloc'd memory and we
should always free it regardless.

thanks
-- PMM
diff mbox

Patch

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 0398cd4..0f9cd2c 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -427,12 +427,16 @@  int arm_load_dtb(const struct arm_boot_info *binfo)
      */
     rom_add_blob_fixed("dtb", fdt, size, binfo->dtb_start);
 
-    g_free(fdt);
+    if (binfo->dtb_filename) {
+        g_free(fdt);
+    }
 
     return size;
 
 fail:
-    g_free(fdt);
+    if (binfo->dtb_filename) {
+        g_free(fdt);
+    }
     return -1;
 }