From patchwork Fri Aug 3 02:59:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 174859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3D89B2C0087 for ; Fri, 3 Aug 2012 13:34:14 +1000 (EST) Received: from localhost ([::1]:32973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx8EC-0006PM-Bn for incoming@patchwork.ozlabs.org; Thu, 02 Aug 2012 23:07:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx8DG-0004mz-BC for qemu-devel@nongnu.org; Thu, 02 Aug 2012 23:06:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sx8DA-00066x-BX for qemu-devel@nongnu.org; Thu, 02 Aug 2012 23:06:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx8DA-00066R-3S for qemu-devel@nongnu.org; Thu, 02 Aug 2012 23:06:00 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7335xmR022822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Aug 2012 23:05:59 -0400 Received: from blackpad.lan.raisama.net (vpn1-5-140.gru2.redhat.com [10.97.5.140]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7335wP5027332; Thu, 2 Aug 2012 23:05:58 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 3085B20417C; Thu, 2 Aug 2012 23:59:34 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 2 Aug 2012 23:59:24 -0300 Message-Id: <1343962766-22024-18-git-send-email-ehabkost@redhat.com> In-Reply-To: <1343962766-22024-1-git-send-email-ehabkost@redhat.com> References: <1343962766-22024-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC 17/19] kill cpu_x86_build_from_name() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We will reorder some code in the CPU object initialization, so move all the cpu_x86_build_from_name() code inside cpu_x86_create(). Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 751cf90..f401a16 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1284,35 +1284,6 @@ error: return -1; } -static int cpu_x86_build_from_name(X86CPUDefinition *x86_cpu_def, - const char *cpu_model) -{ - char *last; - char *s = g_strdup(cpu_model); - char *name = strtok_r(s, ",", &last); - char *featlist = strtok_r(NULL, "", &last); - - if (cpu_x86_find_by_name(x86_cpu_def, name) != 0) { - goto error; - } - - if (cpu_x86_extend_features(x86_cpu_def, featlist) < 0) { - goto error; - } - - if (check_cpuid) { - if (check_features_against_host(x86_cpu_def) && enforce_cpuid) { - goto error; - } - } - g_free(s); - return 0; - -error: - g_free(s); - return -1; -} - /* generate a composite string into buf of all cpuid names in featureset * selected by fbits. indicate truncation at bufsize in the event of overflow. * if flags, suppress names undefined in featureset. @@ -1468,6 +1439,10 @@ X86CPU *cpu_x86_create(const char *cpu_model) X86CPU *cpu; CPUX86State *env; X86CPUDefinition def1, *def = &def1; + char *last; + char *s = g_strdup(cpu_model); + char *name = strtok_r(s, ",", &last); + char *featlist = strtok_r(NULL, "", &last); cpu = X86_CPU(object_new(TYPE_X86_CPU)); env = &cpu->env; @@ -1475,18 +1450,31 @@ X86CPU *cpu_x86_create(const char *cpu_model) memset(def, 0, sizeof(*def)); - if (cpu_x86_build_from_name(def, cpu_model) < 0) { + if (cpu_x86_find_by_name(def, name) != 0) { goto error; } + if (cpu_x86_extend_features(def, featlist) < 0) { + goto error; + } + + if (check_cpuid) { + if (check_features_against_host(def) && enforce_cpuid) { + goto error; + } + } + if (cpu_x86_init_from_def(cpu, def) < 0) { goto error; } x86_cpu_realize(OBJECT(cpu), NULL); + + g_free(s); return cpu; error: + g_free(s); object_delete(OBJECT(cpu)); return NULL; }