Received: from eggs.gnu.org ([208.118.235.92]:51519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1KXM-0005ZL-Bw for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1KXJ-0006GK-Ks for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4672) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1KXJ-0006GF-BJ for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:25 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r11HaOIx022294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Feb 2013 12:36:24 -0500 From: Laszlo Ersek Date: Fri, 1 Feb 2013 18:38:16 +0100 Message-Id: <1359740299-27968-5-git-send-email-lersek@redhat.com> In-Reply-To: <1359740299-27968-1-git-send-email-lersek@redhat.com> References: <1359740299-27968-1-git-send-email-lersek@redhat.com> Subject: [Qemu-devel] [PATCH 4/7] qbus_find_recursive(): reorganize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: lcapitulino@redhat.com, qemu-devel@nongnu.org Eliminate the "match" variable, and move the remaining locals to the narrowest possible scope. Signed-off-by: Laszlo Ersek --- hw/qdev-monitor.c | 35 ++++++++++++++++------------------- 1 files changed, 16 insertions(+), 19 deletions(-) diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 691bab5..284dafa 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -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; } -- 1.7.1