From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcAti-0000Jg-61 for qemu-devel@nongnu.org; Thu, 09 Oct 2014 06:24:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcAtX-0002Lo-Sp for qemu-devel@nongnu.org; Thu, 09 Oct 2014 06:24:38 -0400 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:62297) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcAtX-0002Ld-LI for qemu-devel@nongnu.org; Thu, 09 Oct 2014 06:24:27 -0400 Received: by mail-wi0-f180.google.com with SMTP id em10so1313847wid.1 for ; Thu, 09 Oct 2014 03:24:26 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 9 Oct 2014 12:17:18 +0200 Message-Id: <1412849855-12661-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1412849438-12274-1-git-send-email-pbonzini@redhat.com> References: <1412849438-12274-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 11/28] accel: Move accel name lookup to separate function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost From: Eduardo Habkost Reviewed-by: Paolo Bonzini Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- accel.c | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/accel.c b/accel.c index fc8c551..c752fcc 100644 --- a/accel.c +++ b/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; } } -- 1.8.3.1