From patchwork Wed Jul 9 22:04:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 368827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B9D421400FA for ; Fri, 11 Jul 2014 08:31:24 +1000 (EST) Received: from localhost ([::1]:34056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5006-0008QR-8q for incoming@patchwork.ozlabs.org; Wed, 09 Jul 2014 18:06:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4zz1-0007Sx-14 for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:05:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4zys-0008Hq-WD for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:04:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4zys-0008He-Ln for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:04:50 -0400 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 s69M4oRi014226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 9 Jul 2014 18:04:50 -0400 Received: from localhost (ovpn-113-143.phx2.redhat.com [10.3.113.143]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s69M4ng0022941; Wed, 9 Jul 2014 18:04:49 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 9 Jul 2014 19:04:02 -0300 Message-Id: <1404943462-711-6-git-send-email-ehabkost@redhat.com> In-Reply-To: <1404943462-711-1-git-send-email-ehabkost@redhat.com> References: <1404943462-711-1-git-send-email-ehabkost@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] [RFC 05/25] accel: Move accel name lookup to separate function 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 Signed-off-by: Eduardo Habkost --- hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/hw/core/accel.c b/hw/core/accel.c index 00a71c0..7f9b715 100644 --- a/hw/core/accel.c +++ b/hw/core/accel.c @@ -55,11 +55,24 @@ static AccelType accel_list[] = { { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, }; +/* Lookup AccelType from opt_name. Returns NULL if not found */ +static AccelType *accel_find(const char *opt_name) +{ + int i; + for (i = 0; i < ARRAY_SIZE(accel_list); i++) { + AccelType *acc = &accel_list[i]; + if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) { + return acc; + } + } + return NULL; +} + int configure_accelerator(MachineClass *mc) { const char *p; char buf[10]; - int i, ret; + int ret; bool accel_initialised = false; bool init_failed = false; AccelType *acc = NULL; @@ -75,30 +88,26 @@ int configure_accelerator(MachineClass *mc) p++; } p = get_opt_name(buf, sizeof(buf), p, ':'); - for (i = 0; i < ARRAY_SIZE(accel_list); i++) { - acc = &accel_list[i]; - if (strcmp(acc->opt_name, buf) == 0) { - if (!acc->available()) { - printf("%s not supported for this target\n", - acc->name); - break; - } - *(acc->allowed) = true; - ret = acc->init(mc); - if (ret < 0) { - init_failed = true; - fprintf(stderr, "failed to initialize %s: %s\n", - acc->name, - strerror(-ret)); - *(acc->allowed) = false; - } else { - accel_initialised = true; - } - break; - } - } - if (i == ARRAY_SIZE(accel_list)) { + acc = accel_find(buf); + if (!acc) { fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); + continue; + } + if (!acc->available()) { + printf("%s not supported for this target\n", + acc->name); + continue; + } + *(acc->allowed) = true; + ret = acc->init(mc); + if (ret < 0) { + init_failed = true; + fprintf(stderr, "failed to initialize %s: %s\n", + acc->name, + strerror(-ret)); + *(acc->allowed) = false; + } else { + accel_initialised = true; } }