qdev: Fix device_add bus assumptions
Drop an unreachable fallback bus assignment to SysBus. If no ,bus= is specified, only search busses recursively for bus type if the DeviceClass has a bus_type specified. Handle resulting NULL cases. Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Andreas Färber <afaerber@suse.de> Message-id: 1366077021-28882-1-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
acbbc03661
commit
2f7bd829db
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hw/qdev.h"
|
#include "hw/qdev.h"
|
||||||
|
#include "hw/sysbus.h"
|
||||||
#include "monitor/monitor.h"
|
#include "monitor/monitor.h"
|
||||||
#include "monitor/qdev.h"
|
#include "monitor/qdev.h"
|
||||||
#include "qmp-commands.h"
|
#include "qmp-commands.h"
|
||||||
@ -415,7 +416,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
|||||||
DeviceClass *k;
|
DeviceClass *k;
|
||||||
const char *driver, *path, *id;
|
const char *driver, *path, *id;
|
||||||
DeviceState *qdev;
|
DeviceState *qdev;
|
||||||
BusState *bus;
|
BusState *bus = NULL;
|
||||||
|
|
||||||
driver = qemu_opt_get(opts, "driver");
|
driver = qemu_opt_get(opts, "driver");
|
||||||
if (!driver) {
|
if (!driver) {
|
||||||
@ -453,7 +454,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
|||||||
driver, object_get_typename(OBJECT(bus)));
|
driver, object_get_typename(OBJECT(bus)));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (k->bus_type != NULL) {
|
||||||
bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type);
|
bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type);
|
||||||
if (!bus) {
|
if (!bus) {
|
||||||
qerror_report(QERR_NO_BUS_FOR_DEVICE,
|
qerror_report(QERR_NO_BUS_FOR_DEVICE,
|
||||||
@ -461,18 +462,17 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (qdev_hotplug && !bus->allow_hotplug) {
|
if (qdev_hotplug && bus && !bus->allow_hotplug) {
|
||||||
qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
|
qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bus) {
|
|
||||||
bus = sysbus_get_default();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create device, set properties */
|
/* create device, set properties */
|
||||||
qdev = DEVICE(object_new(driver));
|
qdev = DEVICE(object_new(driver));
|
||||||
|
|
||||||
|
if (bus) {
|
||||||
qdev_set_parent_bus(qdev, bus);
|
qdev_set_parent_bus(qdev, bus);
|
||||||
|
}
|
||||||
|
|
||||||
id = qemu_opts_id(opts);
|
id = qemu_opts_id(opts);
|
||||||
if (id) {
|
if (id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user