From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:43335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMEL8-0004Ky-WC for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMEL6-0002NH-Au for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMEL6-0002Mi-3C for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:40 -0400 From: Thomas Huth Date: Thu, 2 May 2019 18:13:10 +0200 Message-Id: <20190502161310.15624-9-thuth@redhat.com> In-Reply-To: <20190502161310.15624-1-thuth@redhat.com> References: <20190502161310.15624-1-thuth@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 8/8] hw/pci-host: Use object_initialize_child for correct reference counting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , Helge Deller , Eduardo Otubo Both functions, object_initialize() and object_property_add_child() incre= ase 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 chi= ld object might not be properly cleaned up when the parent gets destroyed. Some functions of the pci-host devices miss to drop one of the references= . Fix it by using object_initialize_child() instead, which takes care of calling object_initialize(), object_property_add_child() and object_unref= () in the right order. Suggested-by: Eduardo Habkost Message-Id: <20190430191552.4027-1-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Thomas Huth --- hw/pci-host/designware.c | 4 ++-- hw/pci-host/gpex.c | 5 +++-- hw/pci-host/q35.c | 4 ++-- hw/pci-host/xilinx-pcie.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c index 29ea313798..64ad21d295 100644 --- a/hw/pci-host/designware.c +++ b/hw/pci-host/designware.c @@ -721,8 +721,8 @@ static void designware_pcie_host_init(Object *obj) DesignwarePCIEHost *s =3D DESIGNWARE_PCIE_HOST(obj); DesignwarePCIERoot *root =3D &s->root; =20 - object_initialize(root, sizeof(*root), TYPE_DESIGNWARE_PCIE_ROOT); - object_property_add_child(obj, "root", OBJECT(root), NULL); + object_initialize_child(obj, "root", root, sizeof(*root), + TYPE_DESIGNWARE_PCIE_ROOT, &error_abort, NUL= L); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index 2583b151a4..1bafffcc34 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -29,6 +29,7 @@ * http://www.firmware.org/1275/practice/imap/imap0_9d.pdf */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/hw.h" #include "hw/pci-host/gpex.h" =20 @@ -120,8 +121,8 @@ static void gpex_host_initfn(Object *obj) GPEXHost *s =3D GPEX_HOST(obj); GPEXRootState *root =3D &s->gpex_root; =20 - object_initialize(root, sizeof(*root), TYPE_GPEX_ROOT_DEVICE); - object_property_add_child(obj, "gpex_root", OBJECT(root), NULL); + object_initialize_child(obj, "gpex_root", root, sizeof(*root), + TYPE_GPEX_ROOT_DEVICE, &error_abort, NULL); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 7b871b5734..960939f5ed 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -216,8 +216,8 @@ static void q35_host_initfn(Object *obj) memory_region_init_io(&phb->data_mem, obj, &pci_host_data_le_ops, ph= b, "pci-conf-data", 4); =20 - object_initialize(&s->mch, sizeof(s->mch), TYPE_MCH_PCI_DEVICE); - object_property_add_child(OBJECT(s), "mch", OBJECT(&s->mch), NULL); + object_initialize_child(OBJECT(s), "mch", &s->mch, sizeof(s->mch), + TYPE_MCH_PCI_DEVICE, &error_abort, NULL); qdev_prop_set_int32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(&s->mch), "multifunction", false); /* mch's object_initialize resets the default value, set it again */ diff --git a/hw/pci-host/xilinx-pcie.c b/hw/pci-host/xilinx-pcie.c index 60309afe9e..ceb00e23e6 100644 --- a/hw/pci-host/xilinx-pcie.c +++ b/hw/pci-host/xilinx-pcie.c @@ -149,8 +149,8 @@ static void xilinx_pcie_host_init(Object *obj) XilinxPCIEHost *s =3D XILINX_PCIE_HOST(obj); XilinxPCIERoot *root =3D &s->root; =20 - object_initialize(root, sizeof(*root), TYPE_XILINX_PCIE_ROOT); - object_property_add_child(obj, "root", OBJECT(root), NULL); + object_initialize_child(obj, "root", root, sizeof(*root), + TYPE_XILINX_PCIE_ROOT, &error_abort, NULL); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } --=20 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2056C43219 for ; Thu, 2 May 2019 16:23:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82A5D20645 for ; Thu, 2 May 2019 16:23:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82A5D20645 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([127.0.0.1]:54135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMEUL-0004KY-Rt for qemu-devel@archiver.kernel.org; Thu, 02 May 2019 12:23:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMEL8-0004Ky-WC for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMEL6-0002NH-Au for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMEL6-0002Mi-3C for qemu-devel@nongnu.org; Thu, 02 May 2019 12:13:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F3CD356F6; Thu, 2 May 2019 16:13:39 +0000 (UTC) Received: from thuth.com (ovpn-116-131.ams2.redhat.com [10.36.116.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCD7A17D58; Thu, 2 May 2019 16:13:37 +0000 (UTC) From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Date: Thu, 2 May 2019 18:13:10 +0200 Message-Id: <20190502161310.15624-9-thuth@redhat.com> In-Reply-To: <20190502161310.15624-1-thuth@redhat.com> References: <20190502161310.15624-1-thuth@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 02 May 2019 16:13:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 8/8] hw/pci-host: 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: Eduardo Otubo , Helge Deller , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Message-ID: <20190502161310.1DE7R_kgXv70jHKEoW69otHf2so_7EywSoPtXoN_RxY@z> Both functions, object_initialize() and object_property_add_child() incre= ase 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 chi= ld object might not be properly cleaned up when the parent gets destroyed. Some functions of the pci-host devices miss to drop one of the references= . Fix it by using object_initialize_child() instead, which takes care of calling object_initialize(), object_property_add_child() and object_unref= () in the right order. Suggested-by: Eduardo Habkost Message-Id: <20190430191552.4027-1-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Thomas Huth --- hw/pci-host/designware.c | 4 ++-- hw/pci-host/gpex.c | 5 +++-- hw/pci-host/q35.c | 4 ++-- hw/pci-host/xilinx-pcie.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c index 29ea313798..64ad21d295 100644 --- a/hw/pci-host/designware.c +++ b/hw/pci-host/designware.c @@ -721,8 +721,8 @@ static void designware_pcie_host_init(Object *obj) DesignwarePCIEHost *s =3D DESIGNWARE_PCIE_HOST(obj); DesignwarePCIERoot *root =3D &s->root; =20 - object_initialize(root, sizeof(*root), TYPE_DESIGNWARE_PCIE_ROOT); - object_property_add_child(obj, "root", OBJECT(root), NULL); + object_initialize_child(obj, "root", root, sizeof(*root), + TYPE_DESIGNWARE_PCIE_ROOT, &error_abort, NUL= L); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index 2583b151a4..1bafffcc34 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -29,6 +29,7 @@ * http://www.firmware.org/1275/practice/imap/imap0_9d.pdf */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/hw.h" #include "hw/pci-host/gpex.h" =20 @@ -120,8 +121,8 @@ static void gpex_host_initfn(Object *obj) GPEXHost *s =3D GPEX_HOST(obj); GPEXRootState *root =3D &s->gpex_root; =20 - object_initialize(root, sizeof(*root), TYPE_GPEX_ROOT_DEVICE); - object_property_add_child(obj, "gpex_root", OBJECT(root), NULL); + object_initialize_child(obj, "gpex_root", root, sizeof(*root), + TYPE_GPEX_ROOT_DEVICE, &error_abort, NULL); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 7b871b5734..960939f5ed 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -216,8 +216,8 @@ static void q35_host_initfn(Object *obj) memory_region_init_io(&phb->data_mem, obj, &pci_host_data_le_ops, ph= b, "pci-conf-data", 4); =20 - object_initialize(&s->mch, sizeof(s->mch), TYPE_MCH_PCI_DEVICE); - object_property_add_child(OBJECT(s), "mch", OBJECT(&s->mch), NULL); + object_initialize_child(OBJECT(s), "mch", &s->mch, sizeof(s->mch), + TYPE_MCH_PCI_DEVICE, &error_abort, NULL); qdev_prop_set_int32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(&s->mch), "multifunction", false); /* mch's object_initialize resets the default value, set it again */ diff --git a/hw/pci-host/xilinx-pcie.c b/hw/pci-host/xilinx-pcie.c index 60309afe9e..ceb00e23e6 100644 --- a/hw/pci-host/xilinx-pcie.c +++ b/hw/pci-host/xilinx-pcie.c @@ -149,8 +149,8 @@ static void xilinx_pcie_host_init(Object *obj) XilinxPCIEHost *s =3D XILINX_PCIE_HOST(obj); XilinxPCIERoot *root =3D &s->root; =20 - object_initialize(root, sizeof(*root), TYPE_XILINX_PCIE_ROOT); - object_property_add_child(obj, "root", OBJECT(root), NULL); + object_initialize_child(obj, "root", root, sizeof(*root), + TYPE_XILINX_PCIE_ROOT, &error_abort, NULL); qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); qdev_prop_set_bit(DEVICE(root), "multifunction", false); } --=20 2.21.0