Patchwork [05/28] i386: kvm: extract CPUID entry lookup to cpuid_find_entry() function

login
register
mail settings
Submitter Marcelo Tosatti
Date Oct. 31, 2012, 9:39 a.m.
Message ID <4fb73f1d3be285caeb52a58fa5eaea49bd918650.1351676405.git.mtosatti@redhat.com>
Download mbox | patch
Permalink /patch/195845/
State New
Headers show

Comments

Marcelo Tosatti - Oct. 31, 2012, 9:39 a.m.
From: Eduardo Habkost <ehabkost@redhat.com>

No behavior change, just code movement.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 target-i386/kvm.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 695deb9..c94897f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -145,11 +145,28 @@  static uint32_t cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, int reg)
     return ret;
 }
 
+/* Find matching entry for function/index on kvm_cpuid2 struct
+ */
+static struct kvm_cpuid_entry2 *cpuid_find_entry(struct kvm_cpuid2 *cpuid,
+                                                 uint32_t function,
+                                                 uint32_t index)
+{
+    int i;
+    for (i = 0; i < cpuid->nent; ++i) {
+        if (cpuid->entries[i].function == function &&
+            cpuid->entries[i].index == index) {
+            return &cpuid->entries[i];
+        }
+    }
+    /* not found: */
+    return NULL;
+}
+
 uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
                                       uint32_t index, int reg)
 {
     struct kvm_cpuid2 *cpuid;
-    int i, max;
+    int max;
     uint32_t ret = 0;
     uint32_t cpuid_1_edx;
     bool found = false;
@@ -159,13 +176,10 @@  uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
         max *= 2;
     }
 
-    for (i = 0; i < cpuid->nent; ++i) {
-        if (cpuid->entries[i].function == function &&
-            cpuid->entries[i].index == index) {
-            struct kvm_cpuid_entry2 *entry = &cpuid->entries[i];
-            found = true;
-            ret = cpuid_entry_get_reg(entry, reg);
-        }
+    struct kvm_cpuid_entry2 *entry = cpuid_find_entry(cpuid, function, index);
+    if (entry) {
+        found = true;
+        ret = cpuid_entry_get_reg(entry, reg);
     }
 
     /* Fixups for the data returned by KVM, below */