From patchwork Tue Feb 5 20:39:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 218355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 150802C02BF for ; Wed, 6 Feb 2013 08:22:53 +1100 (EST) Received: from localhost ([::1]:45661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2pyd-0007jl-6D for incoming@patchwork.ozlabs.org; Tue, 05 Feb 2013 16:22:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2pyU-0007ip-Sm for qemu-devel@nongnu.org; Tue, 05 Feb 2013 16:22:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2pHB-00018R-1R for qemu-devel@nongnu.org; Tue, 05 Feb 2013 15:38:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2pHA-000186-Or for qemu-devel@nongnu.org; Tue, 05 Feb 2013 15:37:56 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r15Kbqkp003057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Feb 2013 15:37:52 -0500 Received: from lacos-laptop.usersys.redhat.com (vpn1-5-180.ams2.redhat.com [10.36.5.180]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r15KbRvf020516; Tue, 5 Feb 2013 15:37:49 -0500 From: Laszlo Ersek To: aliguori@us.ibm.com, pbonzini@redhat.com, afaerber@suse.de, lcapitulino@redhat.com, stefanha@linux.vnet.ibm.com, xiawenc@linux.vnet.ibm.com, kwolf@redhat.com, ehabkost@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Tue, 5 Feb 2013 21:39:21 +0100 Message-Id: <1360096768-8863-9-git-send-email-lersek@redhat.com> In-Reply-To: <1360096768-8863-1-git-send-email-lersek@redhat.com> References: <1360096768-8863-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 08/15] qbus_find_recursive(): reorganize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 da32763..64359ee 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -289,38 +289,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; }