Patchwork [RFC,3/6] target-i386: Simplify cpu_x86_find_by_name() logic

login
register
mail settings
Submitter Eduardo Habkost
Date Jan. 4, 2013, 7:56 p.m.
Message ID <1357329382-20944-4-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/209536/
State New
Headers show

Comments

Eduardo Habkost - Jan. 4, 2013, 7:56 p.m.
Move the check for "host" to beginning of function, so instead of a
confusing if/else-if/else mess we now have just two obvious if/else
blocks:

1) Special case for "host";
2) General case for CPU model lookup on x86_defs list.

This way, we will be able to easily move those two parts to separate
class instance_init functions.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6c75327..a2ac3c3 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1250,20 +1250,24 @@  static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)
 
 static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
 {
-    x86_def_t *def;
 
-    for (def = x86_defs; def; def = def->next) {
-        if (name && !strcmp(name, def->name)) {
-            break;
-        }
-    }
     if (kvm_enabled() && name && strcmp(name, "host") == 0) {
 #ifdef CONFIG_KVM
         kvm_cpu_fill_host(x86_cpu_def);
 #endif
-    } else if (!def) {
-        return -1;
     } else {
+        x86_def_t *def;
+
+        for (def = x86_defs; def; def = def->next) {
+            if (name && !strcmp(name, def->name)) {
+                break;
+            }
+        }
+
+        if (!def) {
+            return -1;
+        }
+
         memcpy(x86_cpu_def, def, sizeof(*def));
         /* sysenter isn't supported on compatibility mode on AMD, syscall
          * isn't supported in compatibility mode on Intel.