qemu-e2k/hw/arm
Philippe Mathieu-Daudé 661488b94b hw/arm/bcm2835: Use object_initialize_child for correct ref. counting
As explained in commit aff39be0ed:

  Both functions, object_initialize() and object_property_add_child()
  increase the reference counter of the new object, so one of the
  references has to be dropped afterwards to get the reference
  counting right. Otherwise the child object will not be properly
  cleaned up when the parent gets destroyed.
  Thus let's use now object_initialize_child() instead to get the
  reference counting here right.

This patch was generated using the following Coccinelle script
(with a bit of manual fix-up for overly long lines):

 @use_object_initialize_child@
 expression parent_obj;
 expression child_ptr;
 expression child_name;
 expression child_type;
 expression child_size;
 expression errp;
 @@
 (
 -   object_initialize(child_ptr, child_size, child_type);
 +   object_initialize_child(parent_obj, child_name,  child_ptr, child_size,
 +                           child_type, &error_abort, NULL);
     ... when != parent_obj
 -   object_property_add_child(parent_obj, child_name, OBJECT(child_ptr), NULL);
     ...
 ?-  object_unref(OBJECT(child_ptr));
 |
 -   object_initialize(child_ptr, child_size, child_type);
 +   object_initialize_child(parent_obj, child_name,  child_ptr, child_size,
 +                            child_type, errp, NULL);
     ... when != parent_obj
 -   object_property_add_child(parent_obj, child_name, OBJECT(child_ptr), errp);
     ...
 ?-  object_unref(OBJECT(child_ptr));
 )

 @use_sysbus_init_child_obj@
 expression parent_obj;
 expression dev;
 expression child_ptr;
 expression child_name;
 expression child_type;
 expression child_size;
 expression errp;
 @@
 (
 -   object_initialize_child(parent_obj, child_name, child_ptr, child_size,
 -                           child_type, errp, NULL);
 +   sysbus_init_child_obj(parent_obj, child_name, child_ptr, child_size,
 +                         child_type);
     ...
 -   qdev_set_parent_bus(DEVICE(child_ptr), sysbus_get_default());
 |
 -   object_initialize_child(parent_obj, child_name, child_ptr, child_size,
 -                           child_type, errp, NULL);
 +   sysbus_init_child_obj(parent_obj, child_name, child_ptr, child_size,
 +                         child_type);
 -   dev = DEVICE(child_ptr);
 -   qdev_set_parent_bus(dev, sysbus_get_default());
 )

While the object_initialize() function doesn't take an
'Error *errp' argument, the object_initialize_child() does.
Since this code is used when a machine is created (and is not
yet running), we deliberately choose to use the &error_abort
argument instead of ignoring errors if an object creation failed.
This choice also matches when using sysbus_init_child_obj(),
since its code is:

  void sysbus_init_child_obj(Object *parent,
                             const char *childname, void *child,
                             size_t childsize, const char *childtype)
  {
      object_initialize_child(parent, childname, child, childsize,
                              childtype, &error_abort, NULL);

      qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
  }

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Inspired-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20190507163416.24647-7-philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-05-24 15:29:02 -03:00
..
allwinner-a10.c
armsse.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
armv7m.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
aspeed_soc.c
aspeed.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
bcm2835_peripherals.c hw/arm/bcm2835: Use object_initialize_child for correct ref. counting 2019-05-24 15:29:02 -03:00
bcm2836.c
boot.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
collie.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
cubieboard.c
digic_boards.c
digic.c
exynos4_boards.c hw/arm/exynos4210: QOM'ify the Exynos4210 SoC 2019-05-23 14:47:44 +01:00
exynos4210.c hw/arm/exynos4210: QOM'ify the Exynos4210 SoC 2019-05-23 14:47:44 +01:00
fsl-imx6.c
fsl-imx6ul.c
fsl-imx7.c
fsl-imx25.c
fsl-imx31.c
gumstix.c hw/devices: Move SMSC 91C111 declaration into a new header 2019-04-29 17:57:21 +01:00
highbank.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
imx25_pdk.c
integratorcp.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
Kconfig hw/arm: Express dependencies of the musca machines with Kconfig 2019-05-13 09:36:32 +02:00
kzm.c hw/devices: Move LAN9118 declarations into a new header 2019-04-29 17:57:21 +01:00
mainstone.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
Makefile.objs hw/arm: Express dependencies of the microbit / nrf51 machine with Kconfig 2019-05-13 09:36:32 +02:00
mcimx6ul-evk.c
mcimx7d-sabre.c
microbit.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
mps2-tz.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
mps2.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
msf2-soc.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
msf2-som.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
musca.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
musicpal.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
netduino2.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
nrf51_soc.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
nseries.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
omap1.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
omap2.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
omap_sx1.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
palm.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
pxa2xx_gpio.c
pxa2xx_pic.c
pxa2xx.c
raspi.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
realview.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
sabrelite.c
smmu-common.c hw/arm/smmuv3: Remove SMMUNotifierNode 2019-04-29 17:35:57 +01:00
smmu-internal.h
smmuv3-internal.h Clean up header guards that don't match their file name 2019-05-13 08:58:55 +02:00
smmuv3.c hw/arm/smmuv3: Remove SMMUNotifierNode 2019-04-29 17:35:57 +01:00
spitz.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
stellaris.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
stm32f205_soc.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
strongarm.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
strongarm.h
sysbus-fdt.c
tosa.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
trace-events trace-events: Fix attribution of trace points to source 2019-03-22 16:18:07 +00:00
versatilepb.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
vexpress.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
virt-acpi-build.c hw/arm/virt-acpi-build: pass AcpiMcfgInfo to build_mcfg() 2019-05-20 18:40:02 -04:00
virt.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
xilinx_zynq.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
xlnx-versal-virt.c
xlnx-versal.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00
xlnx-zcu102.c
xlnx-zynqmp.c
z2.c arm: Rename hw/arm/arm.h to hw/arm/boot.h 2019-05-23 14:47:43 +01:00