Message ID | 20200529134523.8477-55-armbru@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | qdev: Rework how we plug into the parent bus | expand |
On 5/29/20 3:45 PM, Markus Armbruster wrote: > So far, qdev_realize() supports only devices that plug into a bus: > argument @bus cannot be null. Extend it to support bus-less devices, > too. > > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > hw/core/qdev.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 78a06db76e..50336168f2 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -408,7 +408,7 @@ void qdev_init_nofail(DeviceState *dev) > /* > * Realize @dev. > * @dev must not be plugged into a bus. > - * Plug @dev into @bus. This takes a reference to @dev. > + * If @bus, plug @dev into @bus. This takes a reference to @dev. > * If @dev has no QOM parent, make one up, taking another reference. > * On success, return true. > * On failure, store an error through @errp and return false. > @@ -418,9 +418,12 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) > Error *err = NULL; > > assert(!dev->realized && !dev->parent_bus); > - assert(bus); This simpler form is easier to review IMHO: if (!bus) { assert(!DEVICE_GET_CLASS(dev)->bus_type); } Whichever you prefer (the simpler the better): Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > > - qdev_set_parent_bus(dev, bus); > + if (bus) { > + qdev_set_parent_bus(dev, bus); > + } else { > + assert(!DEVICE_GET_CLASS(dev)->bus_type); > + } > > object_property_set_bool(OBJECT(dev), true, "realized", &err); > if (err) { >
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 78a06db76e..50336168f2 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -408,7 +408,7 @@ void qdev_init_nofail(DeviceState *dev) /* * Realize @dev. * @dev must not be plugged into a bus. - * Plug @dev into @bus. This takes a reference to @dev. + * If @bus, plug @dev into @bus. This takes a reference to @dev. * If @dev has no QOM parent, make one up, taking another reference. * On success, return true. * On failure, store an error through @errp and return false. @@ -418,9 +418,12 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) Error *err = NULL; assert(!dev->realized && !dev->parent_bus); - assert(bus); - qdev_set_parent_bus(dev, bus); + if (bus) { + qdev_set_parent_bus(dev, bus); + } else { + assert(!DEVICE_GET_CLASS(dev)->bus_type); + } object_property_set_bool(OBJECT(dev), true, "realized", &err); if (err) {
So far, qdev_realize() supports only devices that plug into a bus: argument @bus cannot be null. Extend it to support bus-less devices, too. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- hw/core/qdev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)