[PATCH] commands: usbgadget: improve error message on failure
Ahmad Fatoum
a.fatoum at barebox.org
Wed Nov 5 01:36:38 PST 2025
The command reports EINVAL when encountering an option it doesn't
understand and the help text for other errors.
It's more useful to users to flip them around, so they can see e.g.
-EPERM if a security policy prevented the command from working.
Reported-by: Fabian Pflug <f.pflug at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
commands/usbgadget.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index 1cd8c915b1b1..2edccca1f36c 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -20,7 +20,6 @@ static int do_usbgadget(int argc, char *argv[])
{
struct usbgadget_funcs funcs = {};
int opt;
- int ret;
while ((opt = getopt(argc, argv, "asdA::D::S::b")) > 0) {
switch (opt) {
@@ -47,12 +46,11 @@ static int do_usbgadget(int argc, char *argv[])
usb_multi_unregister();
return 0;
default:
- return -EINVAL;
+ return COMMAND_ERROR_USAGE;
}
}
- ret = usbgadget_prepare_register(&funcs);
- return ret ? COMMAND_ERROR_USAGE : 0;
+ return usbgadget_prepare_register(&funcs);
}
BAREBOX_CMD_HELP_START(usbgadget)
--
2.47.3
More information about the barebox
mailing list