Patchwork [RFC,08/19] i386: extract CPU model lookup to a separate function

login
register
mail settings
Submitter Eduardo Habkost
Date Aug. 3, 2012, 2:59 a.m.
Message ID <1343962766-22024-9-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/174874/
State New
Headers show

Comments

Eduardo Habkost - Aug. 3, 2012, 2:59 a.m.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Patch

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;