From patchwork Thu May 23 15:05:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 165033 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2319193ili; Thu, 23 May 2019 08:07:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrweVnnuiTUjIGHzwcCWDAuaOdS5AgQGyUr9shmqxuGLqiXut7AWbHGhfFu311PVlIDyGC X-Received: by 2002:a17:906:c103:: with SMTP id h3mr55794738ejz.232.1558624067824; Thu, 23 May 2019 08:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558624067; cv=none; d=google.com; s=arc-20160816; b=Cmdcr8nJJz1cHrinAR9wWuz80wrPYvbG3EqTsloHDpIVYKiBS/rLwcZOY978p5bRTI L4w3J2YQs84fiAUhMETgCxizZRAd5GymMPQ3ZtM0XJYHijKDhZOPCezKvdpsAYVXTiKp WjMzjdV/zmCyFh+YC5b4vxETFW87GyIkz9gQX/Euh45k8D5bekgYIf22NgxOgOKITxTK yE0MhwZKOSf4pwt5ktBLx8gu6lx3vfNXyFS7xtzQuyib80f+lONR78MbN9u3W5OwNs8P r5X1ZMBx80FV2tdUgJZyqrgp5tGU0K+8hP2/cIjfCTUCkLuR/bPQF6BqXZteEom6q4a7 YyUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:message-id:date:to:from :dkim-signature; bh=Ume50n8qkYBKGcbQ5wkyvsOh4prOkl3w7x4Kl5qGVnc=; b=Iu+oBqWYhUf9wC9WRHR6H+yqawI2pbHBc/tjVD3+aexUf4W1O0NBE93sieBCxD8OVm 0Abf5+NAWX8ofZyG2FpLfCXH+4gnKcbE0zj90S1hS0RomRlLsNnBs4iFHGSaS9PtD2J1 jbKUWAXj+G2diq76BK2gYVObkogZrkgAbUQmuAvFfIzQ6lahYcgCRhLDAqM6zOHmx9Bt ZkmLrCJFMdQr8gfOZFrPj4f6NnUqEl7sEtpZmjJXWlv+wrpk+SYRpz6P4nkqo/NA9XSO Nj84q3qYUoVHToctlpMbbAeGtm/NypQ421e5e2B02G3VOYoUyQcyjrhuCpqI70DIo2MG NF/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Fpfl0mDd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p15si3736809ejf.148.2019.05.23.08.07.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 May 2019 08:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Fpfl0mDd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:38470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTpJq-0006as-Or for patch@linaro.org; Thu, 23 May 2019 11:07:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTpI0-0004Of-Et for qemu-devel@nongnu.org; Thu, 23 May 2019 11:05:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTpHz-0000P2-3C for qemu-devel@nongnu.org; Thu, 23 May 2019 11:05:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36695) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTpHy-0000MW-FH for qemu-devel@nongnu.org; Thu, 23 May 2019 11:05:50 -0400 Received: by mail-wr1-x443.google.com with SMTP id s17so6696237wru.3 for ; Thu, 23 May 2019 08:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ume50n8qkYBKGcbQ5wkyvsOh4prOkl3w7x4Kl5qGVnc=; b=Fpfl0mDdESslAV3eqgH6v7fmBKDioLGiugegouZenqv4Pa+q6n9wLUuJa2xi+ZC74x 8l7Hb8ISfA0Ycvop0Eteio3pLNgGKGrmbWMljcjJQLDfNXgyJOhUJ57GDtbIQaqM51ED Ij919ZZZ//o1tsmUXzT75avK9ZjM8MmRgkZZgSeATgxvCv+5Ig8vmKjZdAXX1KI50PbR JECNaF3N5X8zJ0UWKzYkJ27Bnk8SNUWG3umFQEngYxoHTaKw8JzEyqjypBRybVq4Ul5J WDnhYq/JlBHSrjCzluidfD/RV8TZbGGQkb+3Mlrp3nP11I3ev5Fv+Vkebn+XETj2mubF /0PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ume50n8qkYBKGcbQ5wkyvsOh4prOkl3w7x4Kl5qGVnc=; b=t8HCVjiE0iqAzvjeuV1ULN5fwB/fDr2KY0LZh2zrkkFSuOncCfonStpLBUWSg4jKS6 qu3xKAZQh4oyrPP2i/JM6vwOk+iX9GnwSWelXe9JbSaI2sfUG1//CazgvwUXf/Q/SA9X k/FduqkLDfOWH89sx7rjGxKf0pQrANQuRfW8mxFSBeAq0jyFWroOFjMw2nXzLwEpjoyr d3ZH7XmSdGXtvAeiP3h4owF0dT90qvfDWJJAXoq2d/AYIAjDIFy93njX8eoSQdzb/7ol hwKGSDkz29yRhkz9noAPH1tJUNkHUJJL9Ef36KhzBhHEeloAnuBRzBLG3SBERkwrdcLv xgbw== X-Gm-Message-State: APjAAAXLYwHMBj7p46StthhNDELaQDdYD4D3q+kf1/G7stz/tZ3/ROo2 uUMWYQBT5mdpqrm/QMxkKivUIGascolDgg== X-Received: by 2002:adf:f7c8:: with SMTP id a8mr2113431wrq.148.1558623946354; Thu, 23 May 2019 08:05:46 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h17sm13739322wrq.79.2019.05.23.08.05.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:05:45 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:05:43 +0100 Message-Id: <20190523150543.22676-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent 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: Damien Hedde , Markus Armbruster Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Markus Armbruster --- v1->v2: clean up also the bus_unparent() code --- hw/core/bus.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- 2.20.1 Reviewed-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé diff --git a/hw/core/bus.c b/hw/core/bus.c index e09843f6abe..b8839c7268d 100644 --- a/hw/core/bus.c +++ b/hw/core/bus.c @@ -96,10 +96,9 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name) bus->parent->num_child_bus++; object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL); object_unref(OBJECT(bus)); - } else if (bus != sysbus_get_default()) { - /* TODO: once all bus devices are qdevified, - only reset handler for main_system_bus should be registered here. */ - qemu_register_reset(qbus_reset_all_fn, bus); + } else { + /* The only bus without a parent is the main system bus */ + assert(bus == sysbus_get_default()); } } @@ -108,18 +107,16 @@ static void bus_unparent(Object *obj) BusState *bus = BUS(obj); BusChild *kid; + /* Only the main system bus has no parent, and that bus is never freed */ + assert(bus->parent); + while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) { DeviceState *dev = kid->child; object_unparent(OBJECT(dev)); } - if (bus->parent) { - QLIST_REMOVE(bus, sibling); - bus->parent->num_child_bus--; - bus->parent = NULL; - } else { - assert(bus != 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 = NULL; } void qbus_create_inplace(void *bus, size_t size, const char *typename,