aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Färber <afaerber@suse.de>2013-01-21 01:00:24 +0100
committerAndreas Färber <afaerber@suse.de>2013-01-27 14:34:27 +0100
commit4bfe910d4728807e7d80de152a7ef33dd608033f (patch)
tree792125a053c7dbe899dc73ba467a37555c090b26
parent8932cfdf7b95734c9b4a114b8ed0b4527af77ce7 (diff)
target-i386: Simplify cpu_x86_find_by_name()
Catch NULL name argument early to avoid repeated checks. Similarly, check for -cpu host early and untangle from iterating through model definitions. This prepares for introducing X86CPU subclasses. Signed-off-by: Andreas Färber <afaerber@suse.de>
-rw-r--r--target-i386/cpu.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c5acaa7523..37a4b03887 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1318,20 +1318,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