tools/x86/kcpuid: Exit the program on invalid parameters
authorAhmed S. Darwish <darwi@linutronix.de>
Mon, 24 Mar 2025 14:20:23 +0000 (15:20 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Mar 2025 08:53:44 +0000 (09:53 +0100)
commita866a6775793a2554585073704b83c4691d80740
tree2f323dcea44cefe3e6850fa1d411059cced883c9
parent116edfe173d0c59ec2aa87fb91f2f31d477b61b3
tools/x86/kcpuid: Exit the program on invalid parameters

If the user passed an invalid CPUID index value through --leaf=index,
kcpuid prints a warning, does nothing, then exits successfully.
Transform the warning to an error, and exit the program with a proper
error code.

Similarly, if the user passed an invalid subleaf, kcpuid prints a
warning, dumps the whole leaf, then exits successfully.  Print a clear
error message regarding the invalid subleaf and exit the program with the
proper error code.

Note, moving the "Invalid input index" message from index_to_func() to
show_info() localizes error message handling to the latter, where it
should be.  It also allows index_to_func() to be refactored at further
commits.

Note, since after this commit and its parent kcpuid does not just "move
on" on failures, remove the NULL parameter check plus silent exit at
show_func() and show_leaf().

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20250324142042.29010-3-darwi@linutronix.de
tools/arch/x86/kcpuid/kcpuid.c