From patchwork Thu Apr 25 17:56:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1091036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44qlRN1ws9z9s3q for ; Fri, 26 Apr 2019 04:03:28 +1000 (AEST) Received: from localhost ([127.0.0.1]:33331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJiiU-0005FU-7p for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2019 14:03:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJicT-0000Lf-SZ for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJicS-00050K-T6 for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hJicS-0004zy-Lc for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBAD5308A11C; Thu, 25 Apr 2019 17:57:11 +0000 (UTC) Received: from localhost (ovpn-116-9.gru2.redhat.com [10.97.116.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2E519729; Thu, 25 Apr 2019 17:57:11 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org, Marcel Apfelbaum Date: Thu, 25 Apr 2019 14:56:53 -0300 Message-Id: <20190425175659.24876-6-ehabkost@redhat.com> In-Reply-To: <20190425175659.24876-1-ehabkost@redhat.com> References: <20190425175659.24876-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 25 Apr 2019 17:57:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/11] vl: Simplify machine_parse() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster Exploit that argument @name is nerver null. Check is_help_option() first, because that's what we do elsewhere. If we (foolishly!) defined a machine named "help", -machine help would now print help instead of selecting the machine named "help". Signed-off-by: Markus Armbruster Reviewed-by: Wei Yang Message-Id: <20190405064121.23662-5-richardw.yang@linux.intel.com> Signed-off-by: Eduardo Habkost --- vl.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/vl.c b/vl.c index 69c530a920..4c794f2bf6 100644 --- a/vl.c +++ b/vl.c @@ -2576,19 +2576,10 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b) static MachineClass *machine_parse(const char *name, GSList *machines) { - MachineClass *mc = NULL; + MachineClass *mc; GSList *el; - if (name) { - mc = find_machine(name, machines); - } - if (mc) { - return mc; - } - if (name && !is_help_option(name)) { - error_report("unsupported machine type"); - error_printf("Use -machine help to list supported machines\n"); - } else { + if (is_help_option(name)) { printf("Supported machines are:\n"); machines = g_slist_sort(machines, machine_class_cmp); for (el = machines; el; el = el->next) { @@ -2600,9 +2591,16 @@ static MachineClass *machine_parse(const char *name, GSList *machines) mc->is_default ? " (default)" : "", mc->deprecation_reason ? " (deprecated)" : ""); } + exit(0); } - exit(!name || !is_help_option(name)); + mc = find_machine(name, machines); + if (!mc) { + error_report("unsupported machine type"); + error_printf("Use -machine help to list supported machines\n"); + exit(1); + } + return mc; } void qemu_add_exit_notifier(Notifier *notify)