From: "tip-bot2 for Ahmed S. Darwish" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Ahmed S. Darwish" <darwi@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/cpu] tools/x86/kcpuid: Simplify usage() handling
Date: Tue, 25 Mar 2025 09:05:45 -0000 [thread overview]
Message-ID: <174289354597.14745.2248278160822769009.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250324142042.29010-4-darwi@linutronix.de>
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 660c29fe53deeb3b3aef1d666ed3bde7608380bd
Gitweb: https://git.kernel.org/tip/660c29fe53deeb3b3aef1d666ed3bde7608380bd
Author: Ahmed S. Darwish <darwi@linutronix.de>
AuthorDate: Mon, 24 Mar 2025 15:20:24 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 25 Mar 2025 09:53:44 +01:00
tools/x86/kcpuid: Simplify usage() handling
Refactor usage() to accept an exit code parameter and exit the program
after usage output. This streamlines its callers' code paths.
Remove the "Invalid option" error message since getopt_long(3) already
emits a similar message by default.
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-4-darwi@linutronix.de
---
tools/arch/x86/kcpuid/kcpuid.c | 37 ++++++++++++++-------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 25b10fe..a90ac0b 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -10,6 +10,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define min(a, b) (((a) < (b)) ? (a) : (b))
+#define __noreturn __attribute__((__noreturn__))
typedef unsigned int u32;
typedef unsigned long long u64;
@@ -584,17 +585,17 @@ static void setup_platform_cpuid(void)
leafs_ext = setup_cpuid_range(0x80000000);
}
-static void usage(void)
+static void __noreturn usage(int exit_code)
{
- warnx("kcpuid [-abdfhr] [-l leaf] [-s subleaf]\n"
- "\t-a|--all Show both bit flags and complex bit fields info\n"
- "\t-b|--bitflags Show boolean flags only\n"
- "\t-d|--detail Show details of the flag/fields (default)\n"
- "\t-f|--flags Specify the CPUID CSV file\n"
- "\t-h|--help Show usage info\n"
- "\t-l|--leaf=index Specify the leaf you want to check\n"
- "\t-r|--raw Show raw CPUID data\n"
- "\t-s|--subleaf=sub Specify the subleaf you want to check"
+ errx(exit_code, "kcpuid [-abdfhr] [-l leaf] [-s subleaf]\n"
+ "\t-a|--all Show both bit flags and complex bit fields info\n"
+ "\t-b|--bitflags Show boolean flags only\n"
+ "\t-d|--detail Show details of the flag/fields (default)\n"
+ "\t-f|--flags Specify the CPUID CSV file\n"
+ "\t-h|--help Show usage info\n"
+ "\t-l|--leaf=index Specify the leaf you want to check\n"
+ "\t-r|--raw Show raw CPUID data\n"
+ "\t-s|--subleaf=sub Specify the subleaf you want to check"
);
}
@@ -610,7 +611,7 @@ static struct option opts[] = {
{ NULL, 0, NULL, 0 }
};
-static int parse_options(int argc, char *argv[])
+static void parse_options(int argc, char *argv[])
{
int c;
@@ -630,9 +631,7 @@ static int parse_options(int argc, char *argv[])
user_csv = optarg;
break;
case 'h':
- usage();
- exit(1);
- break;
+ usage(EXIT_SUCCESS);
case 'l':
/* main leaf */
user_index = strtoul(optarg, NULL, 0);
@@ -645,11 +644,8 @@ static int parse_options(int argc, char *argv[])
user_sub = strtoul(optarg, NULL, 0);
break;
default:
- warnx("Invalid option '%c'", optopt);
- return -1;
- }
-
- return 0;
+ usage(EXIT_FAILURE);
+ }
}
/*
@@ -662,8 +658,7 @@ static int parse_options(int argc, char *argv[])
*/
int main(int argc, char *argv[])
{
- if (parse_options(argc, argv))
- return -1;
+ parse_options(argc, argv);
/* Setup the cpuid leafs of current platform */
setup_platform_cpuid();
next prev parent reply other threads:[~2025-03-25 9:05 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 14:20 [PATCH v3 00/20] tools/x86/kcpuid: Update bitfields to x86-cpuid-db v2.3 Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 01/20] tools/x86/kcpuid: Fix error handling Ahmed S. Darwish
2025-03-25 8:55 ` Ingo Molnar
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 02/20] tools/x86/kcpuid: Exit the program on invalid parameters Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 03/20] tools/x86/kcpuid: Simplify usage() handling Ahmed S. Darwish
2025-03-25 9:05 ` tip-bot2 for Ahmed S. Darwish [this message]
2025-03-24 14:20 ` [PATCH v3 04/20] tools/x86/kcpuid: Save CPUID output in an array Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 05/20] tools/x86/kcpuid: Print correct CPUID output register names Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 06/20] tools/x86/kcpuid: Remove unused local variable Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 07/20] tools/x86/kcpuid: Remove unused global variable Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 08/20] tools/x86/kcpuid: Set function return type to void Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] tools/x86/kcpuid: Set parse_line() " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 09/20] tools/x86/kcpuid: Use C99-style for loops Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 10/20] tools/x86/kcpuid: Use <cpuid.h> intrinsics Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 11/20] tools/x86/kcpuid: Refactor CPUID range handling for future expansion Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 12/20] tools/x86/kcpuid: Extend CPUID index mask macro Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 13/20] tools/x86/kcpuid: Consolidate index validity checks Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 14/20] tools/x86/kcpuid: Filter valid CPUID ranges Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 15/20] tools/x86/kcpuid: Define Transmeta and Centaur index ranges Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 16/20] tools/x86/kcpuid: Update bitfields to x86-cpuid-db v2.0 Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 17/20] tools/x86/kcpuid: Update bitfields to x86-cpuid-db v2.1 Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 18/20] tools/x86/kcpuid: Update bitfields to x86-cpuid-db v2.2 Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 19/20] tools/x86/kcpuid: Update bitfields to x86-cpuid-db v2.3 Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 14:20 ` [PATCH v3 20/20] MAINTAINERS: Include kcpuid under X86 CPUID DATABASE Ahmed S. Darwish
2025-03-25 9:05 ` [tip: x86/cpu] MAINTAINERS: Include the entire kcpuid/ directory under the X86 CPUID DATABASE entry tip-bot2 for Ahmed S. Darwish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=174289354597.14745.2248278160822769009.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=darwi@linutronix.de \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®