From: Markus Armbruster Date: Tue, 9 Jun 2020 12:23:37 +0000 (+0200) Subject: qdev: Assert devices are plugged into a bus that can take them X-Git-Tag: v5.1.0-rc0~74^2~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81cb05732efb36971901c515b007869cc1d3a532;p=thirdparty%2Fqemu.git qdev: Assert devices are plugged into a bus that can take them This would have caught some of the bugs I just fixed. Signed-off-by: Markus Armbruster Reviewed-by: Mark Cave-Ayland Message-Id: <20200609122339.937862-23-armbru@redhat.com> --- diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 9e5538aeaeb..b5b42b2616f 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -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)),