Received: from eggs.gnu.org ([208.118.235.92]:57273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USkjA-0005mw-Dn for qemu-devel@nongnu.org; Thu, 18 Apr 2013 05:02:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USkj5-0007zC-PC for qemu-devel@nongnu.org; Thu, 18 Apr 2013 05:02:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58334) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USkj5-0007z7-HJ for qemu-devel@nongnu.org; Thu, 18 Apr 2013 05:01:55 -0400 Date: Thu, 18 Apr 2013 11:01:51 +0200 From: Igor Mammedov Message-ID: <20130418110151.316c17b6@nial.usersys.redhat.com> In-Reply-To: <20130418104156.7a5349f0@nial.usersys.redhat.com> References: <1366077021-28882-1-git-send-email-afaerber@suse.de> <20130418104156.7a5349f0@nial.usersys.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qdev: Fix device_add bus assumptions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: ehabkost@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com, lcapitulino@redhat.com, Andreas =?ISO-8859-1?B?RuRyYmVy?= On Thu, 18 Apr 2013 10:41:56 +0200 Igor Mammedov wrote: [...] > > - 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() Err, qdev_print() is safe since it's called on bus children only, so it has parent_bus. > > It would be better to add something like this: > // untested > > 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); > } > > > /* 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) { > >