From patchwork Fri Aug 3 02:59:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC,08/19] i386: extract CPU model lookup to a separate function X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 174874 Message-Id: <1343962766-22024-9-git-send-email-ehabkost@redhat.com> To: qemu-devel@nongnu.org Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 2 Aug 2012 23:59:15 -0300 From: Eduardo Habkost List-Id: Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index dd2dc45..e5be586 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1231,16 +1231,10 @@ error: return -1; } -static int cpu_x86_build_from_name(x86_def_t *x86_cpu_def, - const char *cpu_model) +static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name) { x86_def_t *def; - char *last; - char *s = g_strdup(cpu_model); - char *name = strtok_r(s, ",", &last); - char *featlist = strtok_r(NULL, "", &last); - for (def = x86_defs; def; def = def->next) { if (name && !strcmp(name, def->name)) { break; @@ -1254,6 +1248,22 @@ static int cpu_x86_build_from_name(x86_def_t *x86_cpu_def, } else { memcpy(x86_cpu_def, def, sizeof(*def)); } + return 0; +error: + return -1; +} + +static int cpu_x86_build_from_name(x86_def_t *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;