Received: from eggs.gnu.org ([2001:4830:134:3::10]:45711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVlgI-0008Qa-Ni for qemu-devel@nongnu.org; Tue, 16 Feb 2016 14:53:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVlgD-000625-Kp for qemu-devel@nongnu.org; Tue, 16 Feb 2016 14:53:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVlgD-000621-Dn for qemu-devel@nongnu.org; Tue, 16 Feb 2016 14:53:01 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D70B88EA34 for ; Tue, 16 Feb 2016 19:53:00 +0000 (UTC) From: Markus Armbruster References: <1455303747-19776-1-git-send-email-ehabkost@redhat.com> <1455634667-10388-1-git-send-email-armbru@redhat.com> <56C34DDF.4080501@redhat.com> Date: Tue, 16 Feb 2016 20:52:58 +0100 In-Reply-To: <56C34DDF.4080501@redhat.com> (Marcel Apfelbaum's message of "Tue, 16 Feb 2016 18:27:11 +0200") Message-ID: <87wpq4l9et.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 5/4] vl: Clean up machine selection in main(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum Cc: pbonzini@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com Marcel Apfelbaum writes: > On 02/16/2016 04:57 PM, Markus Armbruster wrote: >> We set machine_class to the default first, and update it to the real >> one later. Any use of machine_class in between is almost certainly >> wrong. Set it once and for all instead. >> >> Signed-off-by: Markus Armbruster >> --- >> vl.c | 11 ++++++----- >> 1 file changed, 6 insertions(+), 5 deletions(-) >> >> diff --git a/vl.c b/vl.c >> index 7918e9f..098728c 100644 >> --- a/vl.c >> +++ b/vl.c >> @@ -2748,8 +2748,9 @@ static const QEMUOption *lookup_opt(int argc, char **argv, >> return popt; >> } >> >> -static void set_machine_options(MachineClass **machine_class) >> +static MachineClass *select_machine(MachineClass *dflt) > > Hi Markus, > > I am no fan of "dflt" naming, but I can live with it. > >> { >> + MachineClass *machine_class = dflt; >> const char *optarg; >> QemuOpts *opts; >> Location loc; >> @@ -2761,16 +2762,17 @@ static void set_machine_options(MachineClass **machine_class) >> >> optarg = qemu_opt_get(opts, "type"); >> if (optarg) { >> - *machine_class = machine_parse(optarg); >> + machine_class = machine_parse(optarg); >> } >> >> - if (*machine_class == NULL) { >> + if (!machine_class) { >> error_report("No machine specified, and there is no default"); >> error_printf("Use -machine help to list supported machines\n"); >> exit(1); >> } >> >> loc_pop(&loc); >> + return machine_class; >> } >> >> static int machine_set_property(void *opaque, >> @@ -3075,7 +3077,6 @@ int main(int argc, char **argv, char **envp) >> os_setup_early_signal_handling(); >> >> module_call_init(MODULE_INIT_MACHINE); >> - machine_class = find_default_machine(); >> cpu_model = NULL; >> snapshot = 0; >> cyls = heads = secs = 0; >> @@ -4066,7 +4067,7 @@ int main(int argc, char **argv, char **envp) >> >> replay_configure(icount_opts); >> >> - set_machine_options(&machine_class); >> + machine_class = select_machine(find_default_machine()); > > I like the approach "going all the way", I would > even hide the call to find_default_machine inside select_machine. Good idea. Squashing in: diff --git a/vl.c b/vl.c index 098728c..c0b6747 100644 --- a/vl.c +++ b/vl.c @@ -2748,9 +2748,9 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } -static MachineClass *select_machine(MachineClass *dflt) +static MachineClass *select_machine(void) { - MachineClass *machine_class = dflt; + MachineClass *machine_class = find_default_machine(); const char *optarg; QemuOpts *opts; Location loc; @@ -4067,7 +4067,7 @@ int main(int argc, char **argv, char **envp) replay_configure(icount_opts); - machine_class = select_machine(find_default_machine()); + machine_class = select_machine(); set_memory_options(&ram_slots, &maxram_size, machine_class); > > Reviewed-by: Marcel Apfelbaum Thanks!