Patchwork [17/17] target-i386: cpu_x86_init(): reorder split of CPU string and creation of CPU object

login
register
mail settings
Submitter Eduardo Habkost
Date Nov. 12, 2012, 9:39 p.m.
Message ID <1352756342-13716-18-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/198477/
State New
Headers show

Comments

Eduardo Habkost - Nov. 12, 2012, 9:39 p.m.
A step towards making the creation of CPU objects use the CPU model name
as class name.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e47ec5d..5f2ce7d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1505,19 +1505,13 @@  static int cpudef_2_x86_cpu(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
 X86CPU *cpu_x86_init(const char *cpu_string)
 {
-    X86CPU *cpu;
+    X86CPU *cpu = NULL;
     CPUX86State *env;
     Error *error = NULL;
     X86CPUDefinition def;
     char *name, *features;
     gchar **model_pieces;
 
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
-    env = &cpu->env;
-    env->cpu_model_str = cpu_string;
-
-    memset(&def, 0, sizeof(def));
-
     model_pieces = g_strsplit(cpu_string, ",", 2);
     if (!model_pieces[0]) {
         goto error;
@@ -1525,6 +1519,12 @@  X86CPU *cpu_x86_init(const char *cpu_string)
     name = model_pieces[0];
     features = model_pieces[1];
 
+    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    env = &cpu->env;
+    env->cpu_model_str = cpu_string;
+
+    memset(&def, 0, sizeof(def));
+
     if (cpu_x86_find_cpudef(name, &def, &error) < 0) {
         goto error;
     }
@@ -1546,7 +1546,9 @@  X86CPU *cpu_x86_init(const char *cpu_string)
     return cpu;
 error:
     g_strfreev(model_pieces);
-    object_delete(OBJECT(cpu));
+    if (cpu) {
+        object_delete(OBJECT(cpu));
+    }
     if (error) {
         error_report("cpu_x86_init: %s", error_get_pretty(error));
         error_free(error);