mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Fabian Pflug <f.pflug@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] commands: usbgadget: improve error message on failure
Date: Wed,  5 Nov 2025 10:36:38 +0100	[thread overview]
Message-ID: <20251105093639.1200672-1-a.fatoum@barebox.org> (raw)

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@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@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




             reply	other threads:[~2025-11-05  9:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05  9:36 Ahmad Fatoum [this message]
2025-11-06  7:43 ` Sascha Hauer

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=20251105093639.1200672-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=f.pflug@pengutronix.de \
    /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