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

Bernhard Beschow posted 5 patches 1 month ago
Maintainers: Bernhard Beschow <shentey@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>
[PATCH 3/5] hw/arm/imx8mp-evk: Fix reference count of SoC object
Posted by Bernhard Beschow 1 month ago
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 <gaurav.sharma_7@nxp.com>
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 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