Patchwork [RFC,10/13] cpu_x86_create: reorder parsing of CPU model string and creation of CPU object

login
register
mail settings
Submitter Eduardo Habkost
Date Aug. 16, 2012, 4:59 p.m.
Message ID <1345136352-10756-11-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/178068/
State New
Headers show

Comments

Eduardo Habkost - Aug. 16, 2012, 4:59 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 | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e7f32fc..2e24e00 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1508,18 +1508,19 @@  X86CPU *cpu_x86_create(const char *cpu_model)
     QDict *features = NULL;
     char *name = NULL;
 
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
-    env = &cpu->env;
-    env->cpu_model_str = cpu_model;
-
     /* for CPU subclasses should go into cpu_x86_init() before object_new() */
     compat_normalize_cpu_model(cpu_model, &name, &features, &error);
     if (error_is_set(&error)) {
-        goto error;
+        goto error_normalize;
     }
 
     /* this block should be replaced by CPU subclasses */
     memset(def, 0, sizeof(*def));
+
+    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    env = &cpu->env;
+    env->cpu_model_str = cpu_model;
+
     if (cpu_x86_find_by_name(cpu, def, name, &error) < 0) {
         goto error;
     }
@@ -1538,13 +1539,14 @@  X86CPU *cpu_x86_create(const char *cpu_model)
     x86_cpu_realize(OBJECT(cpu), NULL);
     return cpu;
 error:
+    object_delete(OBJECT(cpu));
+error_normalize:
     QDECREF(features);
     g_free(name);
     if (error_is_set(&error)) {
         fprintf(stderr, "%s\n", error_get_pretty(error));
         error_free(error);
     }
-    object_delete(OBJECT(cpu));
     return NULL;
 }