From nobody Tue Nov 4 23:51:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531424966766972.3899055378104; Thu, 12 Jul 2018 12:49:26 -0700 (PDT) Received: from localhost ([::1]:33769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdhab-0001sy-Qg for importer@patchew.org; Thu, 12 Jul 2018 15:49:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdhX9-0008D8-Fi for qemu-devel@nongnu.org; Thu, 12 Jul 2018 15:45:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdhX6-0001S2-D8 for qemu-devel@nongnu.org; Thu, 12 Jul 2018 15:45:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fdhX6-0001RC-4c for qemu-devel@nongnu.org; Thu, 12 Jul 2018 15:45:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5328630001DA; Thu, 12 Jul 2018 19:45:43 +0000 (UTC) Received: from localhost (ovpn-116-12.gru2.redhat.com [10.97.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C80760F86; Thu, 12 Jul 2018 19:45:39 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 12 Jul 2018 16:45:21 -0300 Message-Id: <20180712194522.31063-3-ehabkost@redhat.com> In-Reply-To: <20180712194522.31063-1-ehabkost@redhat.com> References: <20180712194522.31063-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 12 Jul 2018 19:45:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 2/3] qdev: Document ownership rules of qbus_create*() 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 , "Michael S. Tsirkin" , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The ownership rules of those functions aren't trivial: the caller owns the new object if parent is NULL, otherwise ownership is transferred to the parent. Clarify that on comments. Signed-off-by: Eduardo Habkost Reviewed-by: Marcel Apfelbaum --- include/hw/qdev-core.h | 24 ++++++++++++++++++++++++ hw/core/bus.c | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index f1fd0f8736..27d1ac3781 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -343,8 +343,32 @@ DeviceState *qdev_find_recursive(BusState *bus, const = char *id); typedef int (qbus_walkerfn)(BusState *bus, void *opaque); typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); =20 +/** + * qbus_create_inplace: + * @bus: A pointer to the memory to be used for the bus object. + * @size: The maximum size available at @bus for the bus object. + * @typename: The name of the type of bus to instantiate. + * @parent: parent device + * @name: name for the new bus + * + * Creates bus in place. + * + * If @parent is not NULL the bus will be owned by @parent, otherwise + * the bus will be owned by the caller. + */ void qbus_create_inplace(void *bus, size_t size, const char *typename, DeviceState *parent, const char *name); +/** + * qbus_create: + * @typename: The name of the type of bus to instantiate. + * @parent: parent device + * @name: name for the new bus + * + * Creates bus object. + * + * If @parent is not NULL the returned object will be owned by @parent, + * otherwise it will be owned by the caller. + */ BusState *qbus_create(const char *typename, DeviceState *parent, const cha= r *name); /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, * < 0 if either devfn or busfn terminate walk somewhere in cursio= n, diff --git a/hw/core/bus.c b/hw/core/bus.c index 4651f24486..68a0d5b085 100644 --- a/hw/core/bus.c +++ b/hw/core/bus.c @@ -74,6 +74,7 @@ int qbus_walk_children(BusState *bus, return 0; } =20 +/* If @parent is not NULL, ownership of @bus is transferred to @parent */ static void qbus_realize(BusState *bus, DeviceState *parent, const char *n= ame) { const char *typename =3D object_get_typename(OBJECT(bus)); @@ -102,6 +103,10 @@ static void qbus_realize(BusState *bus, DeviceState *p= arent, const char *name) QLIST_INSERT_HEAD(&bus->parent->child_bus, bus, sibling); bus->parent->num_child_bus++; object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(b= us), NULL); + /* + * object_property_add_child() takes a new reference, drop the + * reference that was transferred to us. + */ object_unref(OBJECT(bus)); } else if (bus !=3D sysbus_get_default()) { /* TODO: once all bus devices are qdevified, --=20 2.18.0.rc1.1.g3f1ff2140