From: Jan Kiszka <jan.kis...@siemens.com> As the user may specify ambiguous device IDs, let's search for their official names first before considering the user-supplied identifiers.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- docs/qdev-device-use.txt | 4 +++- hw/qdev.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt index 74d4960..0160191 100644 --- a/docs/qdev-device-use.txt +++ b/docs/qdev-device-use.txt @@ -25,7 +25,9 @@ omitted in the path. Example: /i440FX-pcihost/PIIX3 abbreviates /i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings. Existing devices can be addressed either via a unique ID if it was -assigned during creation or via the device tree path: +assigned during creation or via the device tree path. In conflicts, +the latter has precedence. A device tree path has the following +structure: /full_bus_address/driver_name[.instance_number] or diff --git a/hw/qdev.c b/hw/qdev.c index 6b4a629..eeadf4a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -535,16 +535,10 @@ static DeviceState *qbus_find_dev(BusState *bus, const char *elem) /* * try to match in order: - * (1) instance id, if present - * (2) driver name [.instance] - * (3) driver alias [.instance], if present + * (1) driver name [.instance] + * (2) driver alias [.instance], if present + * (3) instance id, if present */ - QLIST_FOREACH(dev, &bus->children, sibling) { - if (dev->id && strcmp(dev->id, elem) == 0) { - return dev; - } - } - if (sscanf(elem, "%127[^.].%u", buf, &instance) == 2) { elem = buf; } else { @@ -565,6 +559,12 @@ static DeviceState *qbus_find_dev(BusState *bus, const char *elem) return dev; } } + + QLIST_FOREACH(dev, &bus->children, sibling) { + if (dev->id && strcmp(dev->id, elem) == 0) { + return dev; + } + } return NULL; } -- 1.6.0.2