From patchwork Thu Apr 18 08:41:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 237480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 74E4D2C01E4 for ; Thu, 18 Apr 2013 18:46:23 +1000 (EST) Received: from localhost ([::1]:56280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USkU1-0005GD-NX for incoming@patchwork.ozlabs.org; Thu, 18 Apr 2013 04:46:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USkTl-0005FF-CO for qemu-devel@nongnu.org; Thu, 18 Apr 2013 04:46:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USkTk-0002Ey-1D for qemu-devel@nongnu.org; Thu, 18 Apr 2013 04:46:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48120) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USkPq-00019k-Bx for qemu-devel@nongnu.org; Thu, 18 Apr 2013 04:42:02 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3I8fxUf022552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 18 Apr 2013 04:41:59 -0400 Received: from nial.usersys.redhat.com (dhcp-1-218.brq.redhat.com [10.34.1.218]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3I8fv4b015226; Thu, 18 Apr 2013 04:41:57 -0400 Date: Thu, 18 Apr 2013 10:41:56 +0200 From: Igor Mammedov To: Andreas =?ISO-8859-1?B?RuRyYmVy?= Message-ID: <20130418104156.7a5349f0@nial.usersys.redhat.com> In-Reply-To: <1366077021-28882-1-git-send-email-afaerber@suse.de> References: <1366077021-28882-1-git-send-email-afaerber@suse.de> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: ehabkost@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, lcapitulino@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com Subject: Re: [Qemu-devel] [PATCH] qdev: Fix device_add bus assumptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, 16 Apr 2013 03:50:21 +0200 Andreas Färber wrote: > Drop an unreachable fallback bus assignment to SysBus. > > If no ,bus= is specified, only search busses recursively for bus type if > the DeviceClass has a bus_type specified. Handle resulting NULL cases. > > Signed-off-by: Andreas Färber > --- > qdev-monitor.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/qdev-monitor.c b/qdev-monitor.c > index 9a78ccf..73d7946 100644 > --- a/qdev-monitor.c > +++ b/qdev-monitor.c > @@ -18,6 +18,7 @@ > */ > > #include "hw/qdev.h" > +#include "hw/sysbus.h" > #include "monitor/monitor.h" > #include "monitor/qdev.h" > #include "qmp-commands.h" > @@ -415,7 +416,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) > DeviceClass *k; > const char *driver, *path, *id; > DeviceState *qdev; > - BusState *bus; > + BusState *bus = NULL; > > driver = qemu_opt_get(opts, "driver"); > if (!driver) { > @@ -453,7 +454,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) > driver, object_get_typename(OBJECT(bus))); > return NULL; > } > - } else { > + } else if (k->bus_type != NULL) { > bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type); > if (!bus) { > qerror_report(QERR_NO_BUS_FOR_DEVICE, > @@ -461,18 +462,17 @@ DeviceState *qdev_device_add(QemuOpts *opts) > return NULL; > } > } > - if (qdev_hotplug && !bus->allow_hotplug) { > + if (qdev_hotplug && bus && !bus->allow_hotplug) { > qerror_report(QERR_BUS_NO_HOTPLUG, bus->name); > return NULL; > } > > - if (!bus) { > - bus = sysbus_get_default(); > - } > - I've checked all direct childs of TYPE_DEVICE and they all set k->bus_type, with only one exception of TYPE_CPU. So it should be safe to remove fallback from qdev_device_add POV. However TYPE_CPU breaks assumption that device always has parent_bus set to not NULL in qdev_unplug() and qdev_print() It would be better to add something like this: // untested > /* create device, set properties */ > qdev = DEVICE(object_new(driver)); > - qdev_set_parent_bus(qdev, bus); > + > + if (bus) { > + qdev_set_parent_bus(qdev, bus); > + } > > id = qemu_opts_id(opts); > if (id) { diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 4eb0134..45009ba 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -207,7 +207,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); - if (!dev->parent_bus->allow_hotplug) { + if (dev->parent_bus && !dev->parent_bus->allow_hotplug) { error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return; } diff --git a/qdev-monitor.c b/qdev-monitor.c index 9a78ccf..2476e4e 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -557,7 +557,9 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent); class = object_class_get_parent(class); } while (class != object_class_by_name(TYPE_DEVICE)); - bus_print_dev(dev->parent_bus, mon, dev, indent); + if (dev->parent_bus) { + bus_print_dev(dev->parent_bus, mon, dev, indent); + } QLIST_FOREACH(child, &dev->child_bus, sibling) { qbus_print(mon, child, indent); }