Re: [PATCH 4/7] hw/hexagon: fix machine->fdt leak in qom-test

Brian Cain <[email protected]> Mon, 27 Jul 2026 10:14:31 -0500
Newsgroups org.kernel.vger.linux-cxl,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 7/25/2026 9:00 AM, Marc-André Lureau wrote:
> virt_instance_init() built the FDT unconditionally at QOM
> instance-init time, so simply instantiating the object (e.g. via
> qom-test's introspection, without ever realizing the machine) leaked
> the 1MB FDT blob: machine_finalize() does not free machine->fdt.
>
> Other boards (arm/virt, riscv/virt, ...) build the FDT lazily from
> their MachineClass::init callback, which only runs when the machine
> is actually selected to boot. Do the same here by moving create_fdt()
> into virt_init().
>
> Fixes: 88a8bc7f43ff ("hw/hexagon: Define hexagon "virt" machine")
> Signed-off-by: Marc-AndrĂ© Lureau <[email protected]>
> ---

Reviewed-by: Brian Cain <[email protected]>


>   hw/hexagon/virt.c | 9 +--------
>   1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/hw/hexagon/virt.c b/hw/hexagon/virt.c
> index a3638998b873..b75047250260 100644
> --- a/hw/hexagon/virt.c
> +++ b/hw/hexagon/virt.c
> @@ -175,13 +175,6 @@ static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms)
>   
>   
>   
> -static void virt_instance_init(Object *obj)
> -{
> -    HexagonVirtMachineState *vms = HEXAGON_VIRT_MACHINE(obj);
> -
> -    create_fdt(vms);
> -}
> -
>   void hexagon_load_fdt(const HexagonVirtMachineState *vms)
>   {
>       MachineState *ms = MACHINE(vms);
> @@ -242,6 +235,7 @@ static void virt_init(MachineState *ms)
>       DeviceState *cpu0;
>       int32_t clk_phandle;
>   
> +    create_fdt(vms);
>       qemu_fdt_setprop_string(ms->fdt, "/chosen", "bootargs", ms->kernel_cmdline);
>   
>       vms->sys = get_system_memory();
> @@ -341,7 +335,6 @@ static const TypeInfo virt_machine_types[] = { {
>       .parent = TYPE_HEXAGON_COMMON_MACHINE,
>       .instance_size = sizeof(HexagonVirtMachineState),
>       .class_init = virt_class_init,
> -    .instance_init = virt_instance_init,
>   } };
>   
>   DEFINE_TYPES(virt_machine_types)
>