diff mbox series

[PULL,12/21] hw/arm: Use sysbus_init_child_obj for correct reference counting

Message ID 20190903153633.6651-13-peter.maydell@linaro.org
State Accepted
Commit 5e039af81667c95a6bd5629e1c7f4422a8857ea1
Headers show
Series target-arm queue | expand

Commit Message

Peter Maydell Sept. 3, 2019, 3:36 p.m. UTC
From: Philippe Mathieu-Daudé <philmd@redhat.com>


Both object_initialize() and qdev_set_parent_bus() increase the
reference counter of the new object, so one of the references has
to be dropped afterwards to get the reference counting right.
In machine model code this refcount leak is not particularly
problematic because (unlike devices) machines will never be
created on demand via QMP, and they are never destroyed.
But in any case let's use the new sysbus_init_child_obj() instead
to get the reference counting here right.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Message-id: 20190823143249.8096-4-philmd@redhat.com
[PMM: rewrote commit message]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 hw/arm/exynos4_boards.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.20.1

Comments

Philippe Mathieu-Daudé Sept. 4, 2019, 1:13 p.m. UTC | #1
On 9/3/19 5:36 PM, Peter Maydell wrote:
> From: Philippe Mathieu-Daudé <philmd@redhat.com>

> 

> Both object_initialize() and qdev_set_parent_bus() increase the

> reference counter of the new object, so one of the references has

> to be dropped afterwards to get the reference counting right.

> In machine model code this refcount leak is not particularly

> problematic because (unlike devices) machines will never be

> created on demand via QMP, and they are never destroyed.

> But in any case let's use the new sysbus_init_child_obj() instead

> to get the reference counting here right.

> 

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

> Message-id: 20190823143249.8096-4-philmd@redhat.com

> [PMM: rewrote commit message]


Thank you very much Peter!

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  hw/arm/exynos4_boards.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c

> index f69358a5ba8..2781d8bd419 100644

> --- a/hw/arm/exynos4_boards.c

> +++ b/hw/arm/exynos4_boards.c

> @@ -131,8 +131,8 @@ exynos4_boards_init_common(MachineState *machine,

>      exynos4_boards_init_ram(s, get_system_memory(),

>                              exynos4_board_ram_size[board_type]);

>  

> -    object_initialize(&s->soc, sizeof(s->soc), TYPE_EXYNOS4210_SOC);

> -    qdev_set_parent_bus(DEVICE(&s->soc), sysbus_get_default());

> +    sysbus_init_child_obj(OBJECT(machine), "soc",

> +                          &s->soc, sizeof(s->soc), TYPE_EXYNOS4210_SOC);

>      object_property_set_bool(OBJECT(&s->soc), true, "realized",

>                               &error_fatal);
diff mbox series

Patch

diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c
index f69358a5ba8..2781d8bd419 100644
--- a/hw/arm/exynos4_boards.c
+++ b/hw/arm/exynos4_boards.c
@@ -131,8 +131,8 @@  exynos4_boards_init_common(MachineState *machine,
     exynos4_boards_init_ram(s, get_system_memory(),
                             exynos4_board_ram_size[board_type]);
 
-    object_initialize(&s->soc, sizeof(s->soc), TYPE_EXYNOS4210_SOC);
-    qdev_set_parent_bus(DEVICE(&s->soc), sysbus_get_default());
+    sysbus_init_child_obj(OBJECT(machine), "soc",
+                          &s->soc, sizeof(s->soc), TYPE_EXYNOS4210_SOC);
     object_property_set_bool(OBJECT(&s->soc), true, "realized",
                              &error_fatal);