diff mbox series

[U-Boot,v2,2/2] common: command: Handle USAGE failure separately

Message ID 543fa8173436c09d85df408adbf14cc5d9e0e67d.1529585912.git.michal.simek@xilinx.com
State Accepted
Commit 27eb7bce3943111dd70c19569b60d9a047f06811
Delegated to: Tom Rini
Headers show
Series [U-Boot,v2,1/2] common: command: Use command_ret_t enum values instead of values | expand

Commit Message

Michal Simek June 21, 2018, 12:58 p.m. UTC
command_ret_t enum contains 3 return values but only two are handled
now. Extend cmd_process_error() and handle CMD_RET_USAGE separately.

These commands are affected by this change.
cmd/demo.c
cmd/efi.c
cmd/gpio.c
cmd/qfw.c
cmd/x86/fsp.c
test/dm/cmd_dm.c

And scripts shouldn't be affected because return value is not 0. But
every command implementation can choose what it is correct to pass.
I would expect that RET_USAGE is called when parameters are not
correctly passed (have incorrect value, missing parameters)
and RET_FAILURE when correct parameters are passed but command fails.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v2:
- Separated patch from 1/2
- Extend description in command.h

 common/command.c  | 3 +++
 include/command.h | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Simon Glass June 21, 2018, 7:45 p.m. UTC | #1
On 21 June 2018 at 06:58, Michal Simek <michal.simek@xilinx.com> wrote:
> command_ret_t enum contains 3 return values but only two are handled
> now. Extend cmd_process_error() and handle CMD_RET_USAGE separately.
>
> These commands are affected by this change.
> cmd/demo.c
> cmd/efi.c
> cmd/gpio.c
> cmd/qfw.c
> cmd/x86/fsp.c
> test/dm/cmd_dm.c
>
> And scripts shouldn't be affected because return value is not 0. But
> every command implementation can choose what it is correct to pass.
> I would expect that RET_USAGE is called when parameters are not
> correctly passed (have incorrect value, missing parameters)
> and RET_FAILURE when correct parameters are passed but command fails.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v2:
> - Separated patch from 1/2
> - Extend description in command.h
>
>  common/command.c  | 3 +++
>  include/command.h | 4 +++-
>  2 files changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromum.org>
diff mbox series

Patch

diff --git a/common/command.c b/common/command.c
index a4a8dc601acb..2433a89e0a8e 100644
--- a/common/command.c
+++ b/common/command.c
@@ -547,6 +547,9 @@  enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
 
 int cmd_process_error(cmd_tbl_t *cmdtp, int err)
 {
+	if (err == CMD_RET_USAGE)
+		return CMD_RET_USAGE;
+
 	if (err) {
 		printf("Command '%s' failed: Error %d\n", cmdtp->name, err);
 		return CMD_RET_FAILURE;
diff --git a/include/command.h b/include/command.h
index 04cd1e745cbf..5b1577f3b477 100644
--- a/include/command.h
+++ b/include/command.h
@@ -67,7 +67,9 @@  extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *
  *
  * @cmdtp: Command which caused the error
  * @err: Error code (0 if none, -ve for error, like -EIO)
- * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found
+ * @return 0 (CMD_RET_SUCCESX) if there is not error,
+ *	   1 (CMD_RET_FAILURE) if an error is found
+ *	   -1 (CMD_RET_USAGE) if 'usage' error is found
  */
 int cmd_process_error(cmd_tbl_t *cmdtp, int err);