c313de
From 5354c931f98f2d95d131bf4d490d0e5e057157fe Mon Sep 17 00:00:00 2001
c313de
Message-Id: <5354c931f98f2d95d131bf4d490d0e5e057157fe@dist-git>
c313de
From: Jiri Denemark <jdenemar@redhat.com>
c313de
Date: Fri, 21 Jun 2019 09:25:32 +0200
c313de
Subject: [PATCH] cpu_x86: Introduce virCPUx86DataCmp
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
virCPUx86DataSorter already compares two virCPUx86DataItem structs.
c313de
Let's add a tiny wrapper around it called virCPUx86DataCmp and use it
c313de
instead of open coded comparisons.
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 559ccd7815056af23de24b7a01e8f644d97b6a92)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Message-Id: <9623fdd20059ec6abc7f09c5e7f1e13927c56944.1561068591.git.jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/cpu/cpu_x86.c | 13 ++++++++++---
c313de
 1 file changed, 10 insertions(+), 3 deletions(-)
c313de
c313de
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
c313de
index 0582be63e2..5a09033d2a 100644
c313de
--- a/src/cpu/cpu_x86.c
c313de
+++ b/src/cpu/cpu_x86.c
c313de
@@ -304,6 +304,13 @@ virCPUx86DataSorter(const void *a, const void *b)
c313de
     return 0;
c313de
 }
c313de
 
c313de
+static int
c313de
+virCPUx86DataItemCmp(const virCPUx86DataItem *item1,
c313de
+                     const virCPUx86DataItem *item2)
c313de
+{
c313de
+    return virCPUx86DataSorter(item1, item2);
c313de
+}
c313de
+
c313de
 
c313de
 /* skips all zero CPUID leaves */
c313de
 static virCPUx86DataItemPtr
c313de
@@ -332,9 +339,9 @@ virCPUx86DataGet(const virCPUx86Data *data,
c313de
     size_t i;
c313de
 
c313de
     for (i = 0; i < data->len; i++) {
c313de
-        if (data->items[i].cpuid.eax_in == item->cpuid.eax_in &&
c313de
-            data->items[i].cpuid.ecx_in == item->cpuid.ecx_in)
c313de
-            return data->items + i;
c313de
+        virCPUx86DataItemPtr di = data->items + i;
c313de
+        if (virCPUx86DataItemCmp(di, item) == 0)
c313de
+            return di;
c313de
     }
c313de
 
c313de
     return NULL;
c313de
-- 
c313de
2.22.0
c313de