Philippe Mathieu-Daudé <phi...@redhat.com> writes: > As Thomas Huth explained: > "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@ > identifier parent_obj; > expression child; > expression propname; > expression child_type; > expression errp; > @@ > ( > - object_initialize(&child, sizeof(child), child_type); > - object_property_add_child(parent_obj, propname, OBJECT(&child), NULL); > + object_initialize_child(parent_obj, propname, &child, sizeof(child), > + child_type, &error_abort, NULL); > | > - object_initialize(&child, sizeof(child), child_type); > - object_property_add_child(parent_obj, propname, OBJECT(&child), errp); > + object_initialize_child(parent_obj, propname, &child, sizeof(child), > + child_type, errp, NULL); > ) > > and a bit of manual fix-up for overly long lines. > > Suggested-by: Eduardo Habkost <ehabk...@redhat.com> > Inspired-by: Thomas Huth <th...@redhat.com> > Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com> > --- > hw/arm/aspeed_soc.c | 43 ++++++++++++++++++------------------ > hw/arm/bcm2835_peripherals.c | 41 +++++++++++++++++----------------- > hw/arm/digic.c | 4 ++-- > 3 files changed, 45 insertions(+), 43 deletions(-) > > diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c > index a27233d487..81665f2948 100644 > --- a/hw/arm/aspeed_soc.c > +++ b/hw/arm/aspeed_soc.c > @@ -106,11 +106,11 @@ static void aspeed_soc_init(Object *obj) > AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); > int i; > > - object_initialize(&s->cpu, sizeof(s->cpu), sc->info->cpu_type); > - object_property_add_child(obj, "cpu", OBJECT(&s->cpu), NULL); > + object_initialize_child(obj, "cpu", &s->cpu, sizeof(s->cpu), > + sc->info->cpu_type, &error_abort, NULL);
This flips from "ignore errors" to "abort on error". Quite probably an improvement, but should be mentioned and justified in the commit message. [...]