Message ID | 1359765428-27805-3-git-send-email-afaerber@suse.de |
---|---|
State | New |
Headers | show |
On Sat, 2 Feb 2013 01:37:06 +0100 Andreas Färber <afaerber@suse.de> 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 <afaerber@suse.de> > --- > 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)
Am 04.02.2013 12:14, schrieb Igor Mammedov: > On Sat, 2 Feb 2013 01:37:06 +0100 > Andreas Färber <afaerber@suse.de> wrote: > >> 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 [..] >> @@ -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. Well, we don't want to object_unref() the CPU in the cleanup path, so we would need to set Error* also in the registration case and move it into that code path, that would be possible. Andreas >> + 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)
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: + 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)
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 <afaerber@suse.de> --- target-i386/cpu.c | 50 +++++++++++++++++++++++++++++++------------------- 1 Datei geändert, 31 Zeilen hinzugefügt(+), 19 Zeilen entfernt(-)