[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH qom-cpu-next v3 2/4] target-i386: Split command
From: |
Igor Mammedov |
Subject: |
Re: [Qemu-devel] [PATCH qom-cpu-next v3 2/4] target-i386: Split command line parsing out of cpu_x86_register() |
Date: |
Mon, 4 Feb 2013 12:14:34 +0100 |
On Sat, 2 Feb 2013 01:37:06 +0100
Andreas Färber <address@hidden> wrote:
> In order to instantiate a CPU subtype we will need to know which type,
> so move the cpu_model splitting into cpu_x86_init().
>
> Parameters need to be set on the X86CPU instance, so move
> cpu_x86_parse_featurestr() into cpu_x86_init() as well.
>
> This leaves cpu_x86_register() operating on the model name only.
>
> Signed-off-by: Andreas Färber <address@hidden>
> ---
> target-i386/cpu.c | 50 +++++++++++++++++++++++++++++++-------------------
> 1 Datei geändert, 31 Zeilen hinzugefügt(+), 19 Zeilen entfernt(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e74802b..ee2fd6b 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1516,24 +1516,14 @@ static void filter_features_for_kvm(X86CPU *cpu)
> }
> #endif
>
> -static int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> +static int cpu_x86_register(X86CPU *cpu, const char *name)
> {
> CPUX86State *env = &cpu->env;
> x86_def_t def1, *def = &def1;
> Error *error = NULL;
> - char *name, *features;
> - gchar **model_pieces;
>
> memset(def, 0, sizeof(*def));
>
> - model_pieces = g_strsplit(cpu_model, ",", 2);
> - if (!model_pieces[0]) {
> - error_setg(&error, "Invalid/empty CPU model name");
> - goto out;
> - }
> - name = model_pieces[0];
> - features = model_pieces[1];
> -
> if (cpu_x86_find_by_name(def, name) < 0) {
> error_setg(&error, "Unable to find CPU definition: %s", name);
> goto out;
> @@ -1565,9 +1555,7 @@ static int cpu_x86_register(X86CPU *cpu, const char
> *cpu_model) goto out;
> }
>
> - cpu_x86_parse_featurestr(cpu, features, &error);
> out:
> - g_strfreev(model_pieces);
> if (error) {
> fprintf(stderr, "%s\n", error_get_pretty(error));
> error_free(error);
> @@ -1578,26 +1566,50 @@ out:
>
> X86CPU *cpu_x86_init(const char *cpu_model)
> {
> - X86CPU *cpu;
> + X86CPU *cpu = NULL;
> CPUX86State *env;
> + gchar **model_pieces;
> + char *name, *features;
> Error *error = NULL;
>
> + model_pieces = g_strsplit(cpu_model, ",", 2);
> + if (!model_pieces[0]) {
> + error_setg(&error, "Invalid/empty CPU model name");
> + goto error;
> + }
> + name = model_pieces[0];
> + features = model_pieces[1];
> +
> cpu = X86_CPU(object_new(TYPE_X86_CPU));
> env = &cpu->env;
> env->cpu_model_str = cpu_model;
>
> - if (cpu_x86_register(cpu, cpu_model) < 0) {
> - object_delete(OBJECT(cpu));
> - return NULL;
> + if (cpu_x86_register(cpu, name) < 0) {
> + goto error;
> + }
> +
> + cpu_x86_parse_featurestr(cpu, features, &error);
> + if (error) {
> + goto error;
> }
>
> object_property_set_bool(OBJECT(cpu), true, "realized", &error);
> if (error) {
> + goto error;
> + }
> + g_strfreev(model_pieces);
> + return cpu;
> +
> +error:
Could you use common exit path like it's done in cpu_x86_register()?
That allows to avoid cleanup code duplication on exit.
> + g_strfreev(model_pieces);
> + if (error) {
> + fprintf(stderr, "%s\n", error_get_pretty(error));
> error_free(error);
> + }
> + if (cpu != NULL) {
> object_delete(OBJECT(cpu));
> - return NULL;
> }
> - return cpu;
> + return NULL;
> }
>
> #if !defined(CONFIG_USER_ONLY)
Re: [Qemu-devel] [PATCH qom-cpu-next v3 0/4] target-i386: X86CPU subclasses, Andreas Färber, 2013/02/02