From nobody Sat Apr 26 10:17:34 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;
	dmarc=fail(p=none dis=none)  header.from=linaro.org
ARC-Seal: i=1; a=rsa-sha256; t=1560429085; cv=none;
	d=zoho.com; s=zohoarc;
	b=fa65zXwvIQhU35Rvcn83n0yQUH8S2nYUAan5LggpucN9IgMNxsUPy00cPApsrDwQZbIU1tn2jX1nblnF00pJE3jHA0yyWhx1Zaf9zM/K1AS9TFhWdQsakfjnMoetHJfhPVN7lhIrUThnkcEQd/f0fvZQQcQIuTXmWCZjs9ds+84=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
 s=zohoarc;
	t=1560429085;
 h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results;
	bh=bX4hRH4lVhTWXUt9Xxv5/AT7FDCVaSNWnYXS84dsZh8=;
	b=XoWZqfJ+Qa9lps9Mkz7gaWCG4Dajy8PtTzvCv2+1Dmn71re1sc3ssOf5HtWx84fVcIPLRltJ18fa7kdQvuW+sqK8kA5ZEjylzFtduz5R5rcfK/1MFK4vw5U2hiQbM41PO5d1kVqT9xxobi0NG697mHnWtNXLeZsy58Bn44Hn5HY=
ARC-Authentication-Results: i=1; mx.zoho.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;
	dmarc=fail header.from=<peter.maydell@linaro.org> (p=none dis=none)
 header.from=<peter.maydell@linaro.org>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1560429085665242.38219858042942;
 Thu, 13 Jun 2019 05:31:25 -0700 (PDT)
Received: from localhost ([::1]:39394 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.86_2)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1hbOsX-00079P-BP
	for importer@patchew.org; Thu, 13 Jun 2019 08:30:53 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:58813)
 by lists.gnu.org with esmtp (Exim 4.86_2)
 (envelope-from <peter.maydell@linaro.org>) id 1hbOcz-0007uG-Rg
 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <peter.maydell@linaro.org>) id 1hbOcx-0003zA-Dc
 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:49 -0400
Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:52231)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <peter.maydell@linaro.org>)
 id 1hbOcv-0003ub-5m
 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:45 -0400
Received: by mail-wm1-x343.google.com with SMTP id s3so9965488wms.2
 for <qemu-devel@nongnu.org>; Thu, 13 Jun 2019 05:14:42 -0700 (PDT)
Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148])
 by smtp.gmail.com with ESMTPSA id y6sm2010576wrp.12.2019.06.13.05.14.40
 for <qemu-devel@nongnu.org>
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 13 Jun 2019 05:14:40 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;
 h=from:to:subject:date:message-id:in-reply-to:references:mime-version
 :content-transfer-encoding;
 bh=bX4hRH4lVhTWXUt9Xxv5/AT7FDCVaSNWnYXS84dsZh8=;
 b=WvAXgAMkHfkAb0RVlgzGELM/5iiBMiC4eT16/axY8wTQ+6tmguvh7HbrWvUL0i5CQl
 qlmYHWLcvOr76KlMxLZ1wcp3INz3C6i7dZanzkyxK6rh7neJ+rFMjeKLXXiayElItj7P
 MvsKe8sXqgdpqkK/oHjTwsDXmB/yYTBtkgey5P5b4Vecyk/fml2UF7ZIS0qWy5zjj118
 MP7XnamQ2bYVeTqPfge2/tMtYmwJdXtE3K0xqt6oO0pnnVyNrgp16+7qVlZVmfIVjxDz
 G85poM9KHZjsW//0VYJRBqhLU3zxBOfE1I9TtwbNbu6VBT/Rhu8736TiB7DQcUZQnXil
 haqQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references:mime-version:content-transfer-encoding;
 bh=bX4hRH4lVhTWXUt9Xxv5/AT7FDCVaSNWnYXS84dsZh8=;
 b=SSxxPFM7mw9zkcbmgzpJHCBvn4LWRF6XFiVK+gPmEqWk80tDUYQKdTP/xNHYRdT/nt
 jdjmhnjwUFvspzn6i62JmpyUq5Nfpi18Fqo71Qrg2FK7cYBsKa4GPIZR5R2DU6QTgOeK
 ERWnd/Y81XQj1IkCZHUF2JZMY9Rtsz902hIk7OKhoMfleO7fbV8tjALS+d9NmoLBDbBR
 h37K5Wgm7haniVsiuuQxgm4pT2G4CrdOCpKKn3VEGN4tr6bpB7da4md4FcotOr6zIwM4
 OUratHoIF+cI8jXN4LBibECnsfEgwm6lmN2cYUqDNeVIWvFDBfV89Qs08wky+SxSPaQ8
 1ODA==
X-Gm-Message-State: APjAAAXwgLaCAnqcfuRrorCMPu8qoE/0DOKJKrgNPQIA70sLJaNzW+Gq
 Z0IBLimAseUMxMK6cPKbd2evl1sPFSQh/g==
X-Google-Smtp-Source: 
 APXvYqzlIhbVQFhZkRHvMg+GCPRGCn//2PNeQujRqbTUNYW2C07Dl8qurdQahcamh5agaEtpCI+HhA==
X-Received: by 2002:a1c:c907:: with SMTP id f7mr3639072wmb.142.1560428081281;
 Thu, 13 Jun 2019 05:14:41 -0700 (PDT)
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Date: Thu, 13 Jun 2019 13:13:50 +0100
Message-Id: <20190613121433.5246-6-peter.maydell@linaro.org>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190613121433.5246-1-peter.maydell@linaro.org>
References: <20190613121433.5246-1-peter.maydell@linaro.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2a00:1450:4864:20::343
Subject: [Qemu-devel] [PULL 05/48] hw/core/bus.c: Only the main system bus
 can have no parent
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: fail (Header signature does not verify)

In commit 80376c3fc2c38fdd453 in 2010 we added a workaround for
some qbus buses not being connected to qdev devices -- if the
bus has no parent object then we register a reset function which
resets the bus on system reset (and unregister it when the
bus is unparented).

Nearly a decade later, we have now no buses in the tree which
are created with non-NULL parents, so we can remove the
workaround and instead just assert that if the bus has a NULL
parent then it is the main system bus.

(The absence of other parentless buses was confirmed by
code inspection of all the callsites of qbus_create() and
qbus_create_inplace() and cross-checked by 'make check'.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <philmd@redhat.com>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Tested-by: Philippe Mathieu-Daud=C3=A9 <philmd@redhat.com>
Message-id: 20190523150543.22676-1-peter.maydell@linaro.org
---
 hw/core/bus.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/hw/core/bus.c b/hw/core/bus.c
index e6baa04e52b..17bc1edcde6 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -97,10 +97,9 @@ static void qbus_realize(BusState *bus, DeviceState *par=
ent, const char *name)
         bus->parent->num_child_bus++;
         object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(b=
us), NULL);
         object_unref(OBJECT(bus));
-    } else if (bus !=3D sysbus_get_default()) {
-        /* TODO: once all bus devices are qdevified,
-           only reset handler for main_system_bus should be registered her=
e. */
-        qemu_register_reset(qbus_reset_all_fn, bus);
+    } else {
+        /* The only bus without a parent is the main system bus */
+        assert(bus =3D=3D sysbus_get_default());
     }
 }
=20
@@ -109,18 +108,16 @@ static void bus_unparent(Object *obj)
     BusState *bus =3D BUS(obj);
     BusChild *kid;
=20
+    /* Only the main system bus has no parent, and that bus is never freed=
 */
+    assert(bus->parent);
+
     while ((kid =3D QTAILQ_FIRST(&bus->children)) !=3D NULL) {
         DeviceState *dev =3D kid->child;
         object_unparent(OBJECT(dev));
     }
-    if (bus->parent) {
-        QLIST_REMOVE(bus, sibling);
-        bus->parent->num_child_bus--;
-        bus->parent =3D NULL;
-    } else {
-        assert(bus !=3D sysbus_get_default()); /* main_system_bus is never=
 freed */
-        qemu_unregister_reset(qbus_reset_all_fn, bus);
-    }
+    QLIST_REMOVE(bus, sibling);
+    bus->parent->num_child_bus--;
+    bus->parent =3D NULL;
 }
=20
 void qbus_create_inplace(void *bus, size_t size, const char *typename,
--=20
2.20.1