qemu-patch-raspberry4/hw/virtio
Philippe Mathieu-Daudé 3d2fc923ec hw/virtio: Use object_initialize_child for correct reference counting
As explained in commit aff39be0ed97:

  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:

 @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));
 )

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.

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-4-philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-05-24 15:29:02 -03:00
..
Kconfig s390x: express dependencies with Kconfig 2019-03-07 21:46:19 +01:00
Makefile.objs Add vhost-user-input-pci 2019-05-10 14:52:47 +02:00
trace-events hw/virtio/virtio-mmio: Convert DPRINTF to trace and log 2019-05-22 15:33:20 +02:00
vhost-backend.c vhost-net: revamp configure logic 2019-02-21 12:28:01 -05:00
vhost-scsi-pci.c virtio: split vhost scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-stub.c vhost-user: simplify vhost_user_init/vhost_user_cleanup 2019-03-12 21:22:31 -04:00
vhost-user-blk-pci.c virtio: split vhost user blk bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-user-input-pci.c Add vhost-user-input-pci 2019-05-10 14:52:47 +02:00
vhost-user-scsi-pci.c virtio: split vhost user scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-user.c vhost-user: Support transferring inflight buffer between qemu and backend 2019-03-12 22:31:21 -04:00
vhost-vsock-pci.c virtio: split vhost vsock bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-vsock.c hw: use "qemu/osdep.h" as first #include in source files 2017-12-18 17:07:02 +03:00
vhost.c vhost-user: Support transferring inflight buffer between qemu and backend 2019-03-12 22:31:21 -04:00
virtio-9p-pci.c virtio: split virtio 9p bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-balloon-pci.c virtio: split virtio balloon bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-balloon.c virtio-balloon: Restore MADV_WILLNEED hint on balloon deflate 2019-03-12 21:22:31 -04:00
virtio-blk-pci.c virtio: split virtio blk bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-bus.c virtio: remove event notifier cleanup call on de-assign 2018-02-08 21:06:26 +02:00
virtio-crypto-pci.c hw: report invalid disable-legacy|modern usage for virtio-1-only devs 2019-05-20 18:40:02 -04:00
virtio-crypto.c cryptodev: add vhost support 2018-03-01 18:26:17 +02:00
virtio-input-host-pci.c virtio-input-host-pci: cleanup types 2019-05-13 08:49:30 +02:00
virtio-input-pci.c hw: report invalid disable-legacy|modern usage for virtio-1-only devs 2019-05-20 18:40:02 -04:00
virtio-mmio.c hw/virtio/virtio-mmio: Convert DPRINTF to trace and log 2019-05-22 15:33:20 +02:00
virtio-net-pci.c virtio: split virtio net bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-pci.c pci: Simplify pci_bus_is_root() 2019-05-20 18:40:02 -04:00
virtio-pci.h hw: report invalid disable-legacy|modern usage for virtio-1-only devs 2019-05-20 18:40:02 -04:00
virtio-rng-pci.c virtio: split virtio rng bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-rng.c qom: make user_creatable_complete() specific to UserCreatable 2018-12-11 15:45:22 -02:00
virtio-scsi-pci.c virtio: split virtio scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-serial-pci.c virtio: split virtio serial bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio.c hw/virtio: Use object_initialize_child for correct reference counting 2019-05-24 15:29:02 -03:00