Skip to content

Commit 0150d1b

Browse files
committed
tools/x86/kcpuid: Dump the correct CPUID function in error
The tool uses the 16 least significant bits of the CPUID leaf as an index into its array of CPUID function field descriptions. However, when that index is non-existent, it uses the same, truncated index to report it, which is wrong: $ kcpuid -l 0x80000034 ERR: invalid input index (0x34) Use the original index number in the error message. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ac9a786 commit 0150d1b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/arch/x86/kcpuid/kcpuid.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,16 @@ static void show_range(struct cpuid_range *range)
517517
static inline struct cpuid_func *index_to_func(u32 index)
518518
{
519519
struct cpuid_range *range;
520+
u32 func_idx;
520521

521522
range = (index & 0x80000000) ? leafs_ext : leafs_basic;
522-
index &= 0x7FFFFFFF;
523+
func_idx = index & 0xffff;
523524

524-
if (((index & 0xFFFF) + 1) > (u32)range->nr) {
525+
if ((func_idx + 1) > (u32)range->nr) {
525526
printf("ERR: invalid input index (0x%x)\n", index);
526527
return NULL;
527528
}
528-
return &range->funcs[index];
529+
return &range->funcs[func_idx];
529530
}
530531

531532
static void show_info(void)

0 commit comments

Comments
 (0)