qdev: relax bus type check in qdev_device_add()
PATCH 1/1 qdev: relax bus type check in qdev_device_add()
We are currently checking for an exact type match. Use QOM dynamic_cast to check for a compatible type instead.
--- hw/qdev-monitor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/qdev-monitor.c +6 -1
@@ -431,11 +431,16 @@ DeviceState *qdev_device_add(QemuOpts *opts)/* find bus */ path =qemu_opt_get (opts,"bus" );if (path !=NULL ) { +ObjectClass *bus_class; + bus =qbus_find (path);if (!bus) {return NULL ; } -if (strcmp (object_get_typename (OBJECT (bus)), k->bus_type) !=0 ) { + + bus_class =OBJECT_CLASS (BUS_GET_CLASS (bus)); + +if (!object_class_dynamic_cast (bus_class, k->bus_type)) {qerror_report (QERR_BAD_BUS_FOR_DEVICE , driver,object_get_typename (OBJECT (bus)));return NULL ;
Signature · 1 line
1.8.0
Quoted 2 lines · Anthony Liguori
We are currently checking for an exact type match. Use QOM
dynamic_castto check for a compatible type instead.
I think this only catches the case where a bus was explicitly specified via bus=. For the default case you also need to change the similar code for checking the bus type in qbus_find_recursive(), right?
-- PMM
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Anthony Liguori
We are currently checking for an exact type match. Use QOM
dynamic_castto check for a compatible type instead.I think this only catches the case where a bus was explicitly specified via bus=. For the default case you also need to change the similar code for checking the bus type in
qbus_find_recursive(), right?-- PMM
Right, it's working only with the "bus=" command line.