@@ -288,38 +288,35 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
}
static BusState *qbus_find_recursive(BusState *bus, const char *name,
- const char *bus_typename)
+ const char *type)
{
- BusClass *bus_class = BUS_GET_CLASS(bus);
BusChild *kid;
- BusState *child, *ret;
- int match = 1;
- if (name && (strcmp(bus->name, name) != 0)) {
- match = 0;
- }
- if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
- match = 0;
- }
- if ((bus_class->max_dev != 0) && (bus_class->max_dev <= bus->max_index)) {
+ if ((name == NULL || strcmp(bus->name, name) == 0) &&
+ (type == NULL || object_dynamic_cast(OBJECT(bus), type) != NULL)) {
+ BusClass *bus_class = BUS_GET_CLASS(bus);
+
+ /* name (if any) and type (if any) match; check free slots */
+ if (bus_class->max_dev == 0 || bus->max_index < bus_class->max_dev) {
+ return bus;
+ }
+
+ /* bus is full -- fatal error for search by name */
if (name != NULL) {
- /* bus was explicitly specified: return an error. */
qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
bus->name);
return NULL;
- } else {
- /* bus was not specified: try to find another one. */
- match = 0;
}
}
- if (match) {
- return bus;
- }
QTAILQ_FOREACH(kid, &bus->children, sibling) {
DeviceState *dev = kid->child;
+ BusState *child;
+
QLIST_FOREACH(child, &dev->child_bus, sibling) {
- ret = qbus_find_recursive(child, name, bus_typename);
+ BusState *ret;
+
+ ret = qbus_find_recursive(child, name, type);
if (ret) {
return ret;
}
Eliminate the "match" variable, and move the remaining locals to the narrowest possible scope. Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- hw/qdev-monitor.c | 35 ++++++++++++++++------------------- 1 files changed, 16 insertions(+), 19 deletions(-)