Philippe Mathieu-Daudé <f4...@amsat.org> writes: > Commit 510ef98dca made qdev_realize() support bus-less devices, > asserting either the device is bus-less or the device is created > on a bus. Commit 464a22c757 used qdev_realize() instead of > object_property_set_bool(). Since qdev_realize() now checks for > a bus, it is not possible to create hotplug devices unattached > to any bus anymore. > > Fix by only asserting if the device is not hotpluggable. > > Fixes: 464a22c757 "qdev: Use qdev_realize() in qdev_device_add()" > Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> > --- > hw/core/qdev.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 01796823b4..6c5540ecdc 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -393,7 +393,9 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error > **errp) > if (bus) { > qdev_set_parent_bus(dev, bus); > } else { > - assert(!DEVICE_GET_CLASS(dev)->bus_type); > + DeviceClass *dc = DEVICE_GET_CLASS(dev); > + > + assert(dc->hotpluggable || !dc->bus_type); > } > > return object_property_set_bool(OBJECT(dev), "realized", true, errp);
I think this is wrong. Invariant about realized devices and their bus: * realized "bus-full" devices are plugged into an appropriate bus, and * realized bus-less devices are not plugged into any bus. Since qdev_realize() goes from unrealized to realized, it needs to establish the invariant, regardless of dc->hotpluggable. I suspect the bug is in the caller. Give me a concrete reproducer, and I'll look.