Skip to content

Commit

Permalink
tools/x86/kcpuid: Dump the correct CPUID function in error
Browse files Browse the repository at this point in the history
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) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230426094107.27348-1-bp@alien8.de
  • Loading branch information
Borislav Petkov (AMD) committed May 8, 2023
1 parent ac9a786 commit 0150d1b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tools/arch/x86/kcpuid/kcpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,16 @@ static void show_range(struct cpuid_range *range)
static inline struct cpuid_func *index_to_func(u32 index)
{
struct cpuid_range *range;
u32 func_idx;

range = (index & 0x80000000) ? leafs_ext : leafs_basic;
index &= 0x7FFFFFFF;
func_idx = index & 0xffff;

if (((index & 0xFFFF) + 1) > (u32)range->nr) {
if ((func_idx + 1) > (u32)range->nr) {
printf("ERR: invalid input index (0x%x)\n", index);
return NULL;
}
return &range->funcs[index];
return &range->funcs[func_idx];
}

static void show_info(void)
Expand Down

0 comments on commit 0150d1b

Please sign in to comment.