[PATCH v1 08/12] tools/x86/kcpuid: Restrict CPUID scanning to valid vendor ranges

Ahmed S. Darwish posted 12 patches 11 months, 1 week ago
[PATCH v1 08/12] tools/x86/kcpuid: Restrict CPUID scanning to valid vendor ranges
Posted by Ahmed S. Darwish 11 months, 1 week ago
kcpuid works in two runs: one run for invoking the CPUID instructions and
saving all their output in memory, and another for parsing that raw
in-memory output using the CSV file specification.  In both runs, kcpuid
should only process CPUID ranges that are valid for the current CPU
vendor.

Restrict for_each_cpuid_range() to only iterate over CPUID ranges that
are known to be valid for this CPU vendor.  Doing it at the iterator
level avoids sprinkling ugly CPU-vendor CPUID range validity conditionals
throughout the code.  Overall, this allows adding vendor-specific CPUID
rages to the CSV file at later commits.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
---
 tools/arch/x86/kcpuid/kcpuid.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 36efcb753b77..3153c8eba0c4 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -118,7 +118,9 @@ static char *range_to_str(struct cpuid_range *range)
 
 #define for_each_cpuid_range(range)				\
 	for (unsigned int i = 0;				\
-	     i < ARRAY_SIZE(ranges) && ((range) = &ranges[i]);	\
+	     i < ARRAY_SIZE(ranges)		&&		\
+		     ((range) = &ranges[i])	&&		\
+		     (range->vendors & this_cpu_vendor);	\
 	     i++)
 
 struct cpuid_range *index_to_cpuid_range(u32 index)
-- 
2.48.1