mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] usbgadget: fix error code in common code base
Date: Tue, 21 May 2024 10:06:16 +0200	[thread overview]
Message-ID: <20240521080617.1532603-1-m.felsch@pengutronix.de> (raw)

Don't use command error codes in the common code base. Instead the
commands should convert common error codes into command error codes.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 commands/dfu.c       | 2 +-
 commands/usbgadget.c | 5 +++--
 common/usbgadget.c   | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/commands/dfu.c b/commands/dfu.c
index 2116747f6885..bbe75841b914 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -31,7 +31,7 @@ static int do_dfu(int argc, char *argv[])
 	funcs.dfu_opts = argv[optind];
 	ret = usbgadget_register(&funcs);
 	if (ret)
-		return ret;
+		return COMMAND_ERROR_USAGE;
 
 	command_slice_release();
 	while (!usb_dfu_detached()) {
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index e69660fde541..736ccb5d9185 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -20,6 +20,7 @@ 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) {
@@ -50,8 +51,8 @@ static int do_usbgadget(int argc, char *argv[])
 		}
 	}
 
-
-	return usbgadget_register(&funcs);
+	ret = usbgadget_register(&funcs);
+	return ret ? COMMAND_ERROR_USAGE : 0;
 }
 
 BAREBOX_CMD_HELP_START(usbgadget)
diff --git a/common/usbgadget.c b/common/usbgadget.c
index 371355116364..9974be57d1cb 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -71,7 +71,7 @@ int usbgadget_register(const struct usbgadget_funcs *funcs)
 
 	if (usb_multi_count_functions(opts) == 0) {
 		pr_warn("No functions to register\n");
-		ret = COMMAND_ERROR_USAGE;
+		ret = -EINVAL;
 		goto err;
 	}
 
-- 
2.39.2




             reply	other threads:[~2024-05-21  8:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  8:06 Marco Felsch [this message]
2024-05-21  8:06 ` [PATCH 2/2] usbgadget: split usbgadget_register into prepare and register Marco Felsch
2024-05-21 11:07 ` [PATCH 1/2] usbgadget: fix error code in common code base 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=20240521080617.1532603-1-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.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