Patchwork [qom-cpu,for-1.4,v2,1/2] target-i386: Simplify cpu_x86_find_by_name()

login
register
mail settings
Submitter Andreas Färber
Date Jan. 21, 2013, 1:13 a.m.
Message ID <1358730818-26771-2-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/214022/
State New
Headers show

Comments

Andreas Färber - Jan. 21, 2013, 1:13 a.m.
Catch NULL name argument early to avoid repeated checks.
Similarly, check for -cpu host early and untangle from iterating through
model definitions.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.c |   22 ++++++++++++----------
 1 Datei geändert, 12 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 333745b..a072712 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1321,20 +1321,22 @@  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 (name == NULL) {
+        return -1;
     }
-    if (kvm_enabled() && name && strcmp(name, "host") == 0) {
+    if (kvm_enabled() && strcmp(name, "host") == 0) {
         kvm_cpu_fill_host(x86_cpu_def);
-    } else if (!def) {
-        return -1;
-    } else {
-        memcpy(x86_cpu_def, def, sizeof(*def));
+        return 0;
     }
 
-    return 0;
+    for (def = x86_defs; def; def = def->next) {
+        if (strcmp(name, def->name) == 0) {
+            memcpy(x86_cpu_def, def, sizeof(*def));
+            return 0;
+        }
+    }
+
+    return -1;
 }
 
 /* Parse "+feature,-feature,feature=foo" CPU feature string