[PATCH 3/5] hw/arm/imx8mp-evk: Fix reference count of SoC object

Bernhard Beschow <[email protected]>
Newsgroups org.nongnu.qemu-trivial,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
object_new() leaves a reference count of one, and object_property_add_child()
then leaves it at two. This would leak the SoC object if the machine object was
destroyed since the machine is the SoC's sole owner. Fix this by converting to
object_new_with_props() which gets the parenting and reference count right in
one go.

Fixes: a4eefc69b237 ("hw/arm: Add i.MX 8M Plus EVK board")
cc: Gaurav Sharma <[email protected]>
Signed-off-by: Bernhard Beschow <[email protected]>
---
 hw/arm/imx8mp-evk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c
index b84ac91a17..cfc3038c36 100644
--- a/hw/arm/imx8mp-evk.c
+++ b/hw/arm/imx8mp-evk.c
@@ -74,8 +74,8 @@ static void imx8mp_evk_init(MachineState *machine)
         .modify_dtb = imx8mp_evk_modify_dtb,
     };
 
-    s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP));
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
+    s = FSL_IMX8MP(object_new_with_props(TYPE_FSL_IMX8MP, OBJECT(machine),
+                                         "soc", &error_fatal, NULL));
     object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
 
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.