From patchwork Thu Feb 21 18:38:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1046368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4453Dv2rJgz9s70 for ; Fri, 22 Feb 2019 05:40:15 +1100 (AEDT) Received: from localhost ([127.0.0.1]:36616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtGW-0004O6-Dj for incoming@patchwork.ozlabs.org; Thu, 21 Feb 2019 13:40:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtG2-0004L8-Cw for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:39:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwtFz-0001bQ-KJ for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:39:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58838) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwtFn-00050M-Fl; Thu, 21 Feb 2019 13:39:29 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BC655944A; Thu, 21 Feb 2019 18:38:42 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-77.brq.redhat.com [10.40.204.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 185C71001DD6; Thu, 21 Feb 2019 18:38:33 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Thu, 21 Feb 2019 19:38:29 +0100 Message-Id: <20190221183829.31019-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 21 Feb 2019 18:38:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] hw/arm: Use object_initialize_child for correct reference counting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Thomas Huth , Eduardo Habkost , Antony Pavlov , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Inspired-by: Thomas Huth Signed-off-by: Philippe Mathieu-Daudé --- 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); - object_initialize(&s->scu, sizeof(s->scu), TYPE_ASPEED_SCU); - object_property_add_child(obj, "scu", OBJECT(&s->scu), NULL); + object_initialize_child(obj, "scu", &s->scu, sizeof(s->scu), + TYPE_ASPEED_SCU, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default()); qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev", sc->info->silicon_rev); @@ -121,35 +121,35 @@ static void aspeed_soc_init(Object *obj) object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu), "hw-prot-key", &error_abort); - object_initialize(&s->vic, sizeof(s->vic), TYPE_ASPEED_VIC); - object_property_add_child(obj, "vic", OBJECT(&s->vic), NULL); + object_initialize_child(obj, "vic", &s->vic, sizeof(s->vic), + TYPE_ASPEED_VIC, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->vic), sysbus_get_default()); - object_initialize(&s->timerctrl, sizeof(s->timerctrl), TYPE_ASPEED_TIMER); - object_property_add_child(obj, "timerctrl", OBJECT(&s->timerctrl), NULL); + object_initialize_child(obj, "timerctrl", &s->timerctrl, + sizeof(s->timerctrl), TYPE_ASPEED_TIMER, + &error_abort, NULL); object_property_add_const_link(OBJECT(&s->timerctrl), "scu", OBJECT(&s->scu), &error_abort); qdev_set_parent_bus(DEVICE(&s->timerctrl), sysbus_get_default()); - object_initialize(&s->i2c, sizeof(s->i2c), TYPE_ASPEED_I2C); - object_property_add_child(obj, "i2c", OBJECT(&s->i2c), NULL); + object_initialize_child(obj, "i2c", &s->i2c, sizeof(s->i2c), + TYPE_ASPEED_I2C, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->i2c), sysbus_get_default()); - object_initialize(&s->fmc, sizeof(s->fmc), sc->info->fmc_typename); - object_property_add_child(obj, "fmc", OBJECT(&s->fmc), NULL); + object_initialize_child(obj, "fmc", &s->fmc, sizeof(s->fmc), + sc->info->fmc_typename, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->fmc), sysbus_get_default()); object_property_add_alias(obj, "num-cs", OBJECT(&s->fmc), "num-cs", &error_abort); for (i = 0; i < sc->info->spis_num; i++) { - object_initialize(&s->spi[i], sizeof(s->spi[i]), - sc->info->spi_typename[i]); - object_property_add_child(obj, "spi[*]", OBJECT(&s->spi[i]), NULL); + object_initialize_child(obj, "spi[*]", &s->spi[i], sizeof(s->spi[i]), + sc->info->spi_typename[i], &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->spi[i]), sysbus_get_default()); } - object_initialize(&s->sdmc, sizeof(s->sdmc), TYPE_ASPEED_SDMC); - object_property_add_child(obj, "sdmc", OBJECT(&s->sdmc), NULL); + object_initialize_child(obj, "sdmc", &s->sdmc, sizeof(s->sdmc), + TYPE_ASPEED_SDMC, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->sdmc), sysbus_get_default()); qdev_prop_set_uint32(DEVICE(&s->sdmc), "silicon-rev", sc->info->silicon_rev); @@ -159,15 +159,16 @@ static void aspeed_soc_init(Object *obj) "max-ram-size", &error_abort); for (i = 0; i < sc->info->wdts_num; i++) { - object_initialize(&s->wdt[i], sizeof(s->wdt[i]), TYPE_ASPEED_WDT); - object_property_add_child(obj, "wdt[*]", OBJECT(&s->wdt[i]), NULL); + object_initialize_child(obj, "wdt[*]", &s->wdt[i], sizeof(s->wdt[i]), + TYPE_ASPEED_WDT, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->wdt[i]), sysbus_get_default()); qdev_prop_set_uint32(DEVICE(&s->wdt[i]), "silicon-rev", sc->info->silicon_rev); } - object_initialize(&s->ftgmac100, sizeof(s->ftgmac100), TYPE_FTGMAC100); - object_property_add_child(obj, "ftgmac100", OBJECT(&s->ftgmac100), NULL); + object_initialize_child(obj, "ftgmac100", &s->ftgmac100, + sizeof(s->ftgmac100), TYPE_FTGMAC100, + &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->ftgmac100), sysbus_get_default()); } diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 6be7660e8c..0355a41d8b 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -41,8 +41,8 @@ static void bcm2835_peripherals_init(Object *obj) MBOX_CHAN_COUNT << MBOX_AS_CHAN_SHIFT); /* Interrupt Controller */ - object_initialize(&s->ic, sizeof(s->ic), TYPE_BCM2835_IC); - object_property_add_child(obj, "ic", OBJECT(&s->ic), NULL); + object_initialize_child(obj, "ic", &s->ic, sizeof(s->ic), TYPE_BCM2835_IC, + &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->ic), sysbus_get_default()); /* UART0 */ @@ -51,21 +51,21 @@ static void bcm2835_peripherals_init(Object *obj) qdev_set_parent_bus(DEVICE(s->uart0), sysbus_get_default()); /* AUX / UART1 */ - object_initialize(&s->aux, sizeof(s->aux), TYPE_BCM2835_AUX); - object_property_add_child(obj, "aux", OBJECT(&s->aux), NULL); + object_initialize_child(obj, "aux", &s->aux, sizeof(s->aux), + TYPE_BCM2835_AUX, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->aux), sysbus_get_default()); /* Mailboxes */ - object_initialize(&s->mboxes, sizeof(s->mboxes), TYPE_BCM2835_MBOX); - object_property_add_child(obj, "mbox", OBJECT(&s->mboxes), NULL); + object_initialize_child(obj, "mbox", &s->mboxes, sizeof(s->mboxes), + TYPE_BCM2835_MBOX, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->mboxes), sysbus_get_default()); object_property_add_const_link(OBJECT(&s->mboxes), "mbox-mr", OBJECT(&s->mbox_mr), &error_abort); /* Framebuffer */ - object_initialize(&s->fb, sizeof(s->fb), TYPE_BCM2835_FB); - object_property_add_child(obj, "fb", OBJECT(&s->fb), NULL); + object_initialize_child(obj, "fb", &s->fb, sizeof(s->fb), TYPE_BCM2835_FB, + &error_abort, NULL); object_property_add_alias(obj, "vcram-size", OBJECT(&s->fb), "vcram-size", &error_abort); qdev_set_parent_bus(DEVICE(&s->fb), sysbus_get_default()); @@ -74,8 +74,9 @@ static void bcm2835_peripherals_init(Object *obj) OBJECT(&s->gpu_bus_mr), &error_abort); /* Property channel */ - object_initialize(&s->property, sizeof(s->property), TYPE_BCM2835_PROPERTY); - object_property_add_child(obj, "property", OBJECT(&s->property), NULL); + object_initialize_child(obj, "property", &s->property, + sizeof(s->property), TYPE_BCM2835_PROPERTY, + &error_abort, NULL); object_property_add_alias(obj, "board-rev", OBJECT(&s->property), "board-rev", &error_abort); qdev_set_parent_bus(DEVICE(&s->property), sysbus_get_default()); @@ -86,31 +87,31 @@ static void bcm2835_peripherals_init(Object *obj) OBJECT(&s->gpu_bus_mr), &error_abort); /* Random Number Generator */ - object_initialize(&s->rng, sizeof(s->rng), TYPE_BCM2835_RNG); - object_property_add_child(obj, "rng", OBJECT(&s->rng), NULL); + object_initialize_child(obj, "rng", &s->rng, sizeof(s->rng), + TYPE_BCM2835_RNG, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->rng), sysbus_get_default()); /* Extended Mass Media Controller */ - object_initialize(&s->sdhci, sizeof(s->sdhci), TYPE_SYSBUS_SDHCI); - object_property_add_child(obj, "sdhci", OBJECT(&s->sdhci), NULL); + object_initialize_child(obj, "sdhci", &s->sdhci, sizeof(s->sdhci), + TYPE_SYSBUS_SDHCI, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->sdhci), sysbus_get_default()); /* SDHOST */ - object_initialize(&s->sdhost, sizeof(s->sdhost), TYPE_BCM2835_SDHOST); - object_property_add_child(obj, "sdhost", OBJECT(&s->sdhost), NULL); + object_initialize_child(obj, "sdhost", &s->sdhost, sizeof(s->sdhost), + TYPE_BCM2835_SDHOST, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->sdhost), sysbus_get_default()); /* DMA Channels */ - object_initialize(&s->dma, sizeof(s->dma), TYPE_BCM2835_DMA); - object_property_add_child(obj, "dma", OBJECT(&s->dma), NULL); + object_initialize_child(obj, "dma", &s->dma, sizeof(s->dma), + TYPE_BCM2835_DMA, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->dma), sysbus_get_default()); object_property_add_const_link(OBJECT(&s->dma), "dma-mr", OBJECT(&s->gpu_bus_mr), &error_abort); /* GPIO */ - object_initialize(&s->gpio, sizeof(s->gpio), TYPE_BCM2835_GPIO); - object_property_add_child(obj, "gpio", OBJECT(&s->gpio), NULL); + object_initialize_child(obj, "gpio", &s->gpio, sizeof(s->gpio), + TYPE_BCM2835_GPIO, &error_abort, NULL); qdev_set_parent_bus(DEVICE(&s->gpio), sysbus_get_default()); object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhci", diff --git a/hw/arm/digic.c b/hw/arm/digic.c index 726abb9b48..14409ef080 100644 --- a/hw/arm/digic.c +++ b/hw/arm/digic.c @@ -35,8 +35,8 @@ static void digic_init(Object *obj) DeviceState *dev; int i; - object_initialize(&s->cpu, sizeof(s->cpu), "arm946-" TYPE_ARM_CPU); - object_property_add_child(obj, "cpu", OBJECT(&s->cpu), NULL); + object_initialize_child(obj, "cpu", &s->cpu, sizeof(s->cpu), + "arm946-" TYPE_ARM_CPU, &error_abort, NULL); for (i = 0; i < DIGIC4_NB_TIMERS; i++) { #define DIGIC_TIMER_NAME_MLEN 11