From patchwork Thu Aug 16 16:59:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC, 10/13] cpu_x86_create: reorder parsing of CPU model string and creation of CPU object From: Eduardo Habkost X-Patchwork-Id: 178068 Message-Id: <1345136352-10756-11-git-send-email-ehabkost@redhat.com> To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, gleb@redhat.com, vijaymohan.pandarathil@hp.com, jan.kiszka@siemens.com, mtosatti@redhat.com, mdroth@linux.vnet.ibm.com, blauwirbel@gmail.com, avi@redhat.com, pbonzini@redhat.com, akong@redhat.com, lersek@redhat.com, afaerber@suse.de Date: Thu, 16 Aug 2012 13:59:09 -0300 A step towards making the creation of CPU objects use the CPU model name as class name. Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; }