qdev: Fix -device and device_add to handle unsuitable bus gracefully
authorMarkus Armbruster <armbru@redhat.com>
Fri, 19 Feb 2010 18:08:45 +0000 (19:08 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 16 Mar 2010 15:58:32 +0000 (16:58 +0100)
"device_add isa-serial,bus=pci.0" kills QEMU.  Not good.

hw/qdev.c

index 8bf86a5..3fe811f 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -204,6 +204,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     path = qemu_opt_get(opts, "bus");
     if (path != NULL) {
         bus = qbus_find(path);
+        if (bus && bus->info != info->bus_info) {
+            error_report("Device '%s' can't go on a %s bus",
+                         driver, bus->info->name);
+            return NULL;
+        }
     } else {
         bus = qbus_find_recursive(main_system_bus, NULL, info->bus_info);
     }