From nobody Sun Nov 9 16:22:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551159682759272.51155831342646; Mon, 25 Feb 2019 21:41:22 -0800 (PST) Received: from localhost ([127.0.0.1]:49735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyVUV-0007PR-Pb for importer@patchew.org; Tue, 26 Feb 2019 00:41:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyUmX-0006dY-LJ for qemu-devel@nongnu.org; Mon, 25 Feb 2019 23:55:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyUmR-000460-B6 for qemu-devel@nongnu.org; Mon, 25 Feb 2019 23:55:50 -0500 Received: from ozlabs.org ([203.11.71.1]:46783) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyUmQ-0003F9-JU; Mon, 25 Feb 2019 23:55:47 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 447mfR0y0cz9sPH; Tue, 26 Feb 2019 15:53:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1551156799; bh=ME47+GOHJAuvhYstmqtx4SuXJp/B/DxlS6MHDa+/+lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T9Y2JEsDMq72Alf7kdfeYm0u1lyXWrSt3cs/jtUXCXjt1RDIcIV3SfDdM0d4uUZFh f4/04SxdwErDb2fbMqQd88O/YsLO00RFCWpa+S6y6dJSHtLz3EwRnLtpKqPUdJWp/L LhC7hYMfLYALAdiKKsfsfTQkxz7N+U+hh0Bm65ig= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 26 Feb 2019 15:53:01 +1100 Message-Id: <20190226045304.25618-48-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226045304.25618-1-david@gibson.dropbear.id.au> References: <20190226045304.25618-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 47/50] hw/ppc: 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: lvivier@redhat.com, Thomas Huth , Eduardo Habkost , gkurz@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Thomas Huth 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. Suggested-by: Eduardo Habkost Signed-off-by: Thomas Huth Message-Id: <1550748288-30598-1-git-send-email-thuth@redhat.com> Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: David Gibson --- hw/intc/spapr_xive.c | 11 +++++------ hw/ppc/pnv.c | 12 ++++++------ hw/ppc/pnv_psi.c | 4 ++-- hw/ppc/spapr.c | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c index 06e3c9fdbf..e0e5cb5d8e 100644 --- a/hw/intc/spapr_xive.c +++ b/hw/intc/spapr_xive.c @@ -244,13 +244,12 @@ static void spapr_xive_instance_init(Object *obj) { sPAPRXive *xive =3D SPAPR_XIVE(obj); =20 - object_initialize(&xive->source, sizeof(xive->source), TYPE_XIVE_SOURC= E); - object_property_add_child(obj, "source", OBJECT(&xive->source), NULL); + object_initialize_child(obj, "source", &xive->source, sizeof(xive->sou= rce), + TYPE_XIVE_SOURCE, &error_abort, NULL); =20 - object_initialize(&xive->end_source, sizeof(xive->end_source), - TYPE_XIVE_END_SOURCE); - object_property_add_child(obj, "end_source", OBJECT(&xive->end_source), - NULL); + object_initialize_child(obj, "end_source", &xive->end_source, + sizeof(xive->end_source), TYPE_XIVE_END_SOURCE, + &error_abort, NULL); } =20 static void spapr_xive_realize(DeviceState *dev, Error **errp) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index da540860a2..9e03e9c336 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -736,18 +736,18 @@ static void pnv_chip_power8_instance_init(Object *obj) { Pnv8Chip *chip8 =3D PNV8_CHIP(obj); =20 - object_initialize(&chip8->psi, sizeof(chip8->psi), TYPE_PNV_PSI); - object_property_add_child(obj, "psi", OBJECT(&chip8->psi), NULL); + object_initialize_child(obj, "psi", &chip8->psi, sizeof(chip8->psi), + TYPE_PNV_PSI, &error_abort, NULL); object_property_add_const_link(OBJECT(&chip8->psi), "xics", OBJECT(qdev_get_machine()), &error_abor= t); =20 - object_initialize(&chip8->lpc, sizeof(chip8->lpc), TYPE_PNV_LPC); - object_property_add_child(obj, "lpc", OBJECT(&chip8->lpc), NULL); + object_initialize_child(obj, "lpc", &chip8->lpc, sizeof(chip8->lpc), + TYPE_PNV_LPC, &error_abort, NULL); object_property_add_const_link(OBJECT(&chip8->lpc), "psi", OBJECT(&chip8->psi), &error_abort); =20 - object_initialize(&chip8->occ, sizeof(chip8->occ), TYPE_PNV_OCC); - object_property_add_child(obj, "occ", OBJECT(&chip8->occ), NULL); + object_initialize_child(obj, "occ", &chip8->occ, sizeof(chip8->occ), + TYPE_PNV_OCC, &error_abort, NULL); object_property_add_const_link(OBJECT(&chip8->occ), "psi", OBJECT(&chip8->psi), &error_abort); } diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c index 8ced095063..44bc0cbf58 100644 --- a/hw/ppc/pnv_psi.c +++ b/hw/ppc/pnv_psi.c @@ -444,8 +444,8 @@ static void pnv_psi_init(Object *obj) { PnvPsi *psi =3D PNV_PSI(obj); =20 - object_initialize(&psi->ics, sizeof(psi->ics), TYPE_ICS_SIMPLE); - object_property_add_child(obj, "ics-psi", OBJECT(&psi->ics), NULL); + object_initialize_child(obj, "ics-psi", &psi->ics, sizeof(psi->ics), + TYPE_ICS_SIMPLE, &error_abort, NULL); } =20 static const uint8_t irq_to_xivr[] =3D { diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5d8b8c9e53..b6a571b6f1 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1776,9 +1776,9 @@ static void spapr_create_nvram(sPAPRMachineState *spa= pr) =20 static void spapr_rtc_create(sPAPRMachineState *spapr) { - object_initialize(&spapr->rtc, sizeof(spapr->rtc), TYPE_SPAPR_RTC); - object_property_add_child(OBJECT(spapr), "rtc", OBJECT(&spapr->rtc), - &error_fatal); + object_initialize_child(OBJECT(spapr), "rtc", + &spapr->rtc, sizeof(spapr->rtc), TYPE_SPAPR_RT= C, + &error_fatal, NULL); object_property_set_bool(OBJECT(&spapr->rtc), true, "realized", &error_fatal); object_property_add_alias(OBJECT(spapr), "rtc-time", OBJECT(&spapr->rt= c), --=20 2.20.1