qdev: Assert devices are plugged into a bus that can take them
authorMarkus Armbruster <armbru@redhat.com>
Tue, 9 Jun 2020 12:23:37 +0000 (14:23 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 15 Jun 2020 19:36:30 +0000 (21:36 +0200)
This would have caught some of the bugs I just fixed.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20200609122339.937862-23-armbru@redhat.com>

hw/core/qdev.c

index 9e5538aeaebd999407f54ac2cebc7a12f7acb374..b5b42b2616f7fe1e1981b1fb157b9241f3454440 100644 (file)
@@ -97,6 +97,9 @@ static void bus_add_child(BusState *bus, DeviceState *child)
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 {
     BusState *old_parent_bus = dev->parent_bus;
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
+
+    assert(dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type));
 
     if (old_parent_bus) {
         trace_qdev_update_parent_bus(dev, object_get_typename(OBJECT(dev)),