From da7991b38e1f6d9b172a72650286be2558dc447f Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Tue, 26 Jan 2021 11:44:37 -0500 Subject: cmd: pwm: Rework argc sanity checking Currently, we check argc in a number of places to make sure that we have all of the required arguments for each of the pwm sub-commands. However, there's at least one place where we've got dead code as we'll never have argc == 0, due to checking that argc was at least 4 earlier and having only subtracted 3. Rework things so that when we have determined our subcommand make sure we have the right number of arguments for it, or error out. This means we can stop checking against argc again later. Reported-by: Coverity (CID: 316601) Cc: Pragnesh Patel Signed-off-by: Tom Rini --- cmd/pwm.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'cmd') diff --git a/cmd/pwm.c b/cmd/pwm.c index 5849fc57b66..e1f97c759d2 100644 --- a/cmd/pwm.c +++ b/cmd/pwm.c @@ -34,11 +34,9 @@ static int do_pwm(struct cmd_tbl *cmdtp, int flag, int argc, argc -= 2; argv += 2; - if (argc > 0) { - str_pwm = *argv; - argc--; - argv++; - } + str_pwm = *argv; + argc--; + argv++; if (!str_pwm) return CMD_RET_USAGE; @@ -46,15 +44,23 @@ static int do_pwm(struct cmd_tbl *cmdtp, int flag, int argc, switch (*str_cmd) { case 'i': sub_cmd = PWM_SET_INVERT; + if (argc != 2) + return CMD_RET_USAGE; break; case 'c': sub_cmd = PWM_SET_CONFIG; + if (argc != 3) + return CMD_RET_USAGE; break; case 'e': sub_cmd = PWM_SET_ENABLE; + if (argc != 1) + return CMD_RET_USAGE; break; case 'd': sub_cmd = PWM_SET_DISABLE; + if (argc != 1) + return CMD_RET_USAGE; break; default: return CMD_RET_USAGE; @@ -67,38 +73,29 @@ static int do_pwm(struct cmd_tbl *cmdtp, int flag, int argc, return cmd_process_error(cmdtp, ret); } - if (argc > 0) { - str_channel = *argv; - channel = simple_strtoul(str_channel, NULL, 10); - argc--; - argv++; - } else { - return CMD_RET_USAGE; - } + str_channel = *argv; + channel = simple_strtoul(str_channel, NULL, 10); + argc--; + argv++; - if (sub_cmd == PWM_SET_INVERT && argc > 0) { + if (sub_cmd == PWM_SET_INVERT) { str_enable = *argv; pwm_enable = simple_strtoul(str_enable, NULL, 10); ret = pwm_set_invert(dev, channel, pwm_enable); - } else if (sub_cmd == PWM_SET_CONFIG && argc == 2) { + } else if (sub_cmd == PWM_SET_CONFIG) { str_period = *argv; argc--; argv++; period_ns = simple_strtoul(str_period, NULL, 10); - if (argc > 0) { - str_duty = *argv; - duty_ns = simple_strtoul(str_duty, NULL, 10); - } + str_duty = *argv; + duty_ns = simple_strtoul(str_duty, NULL, 10); ret = pwm_set_config(dev, channel, period_ns, duty_ns); } else if (sub_cmd == PWM_SET_ENABLE) { ret = pwm_set_enable(dev, channel, 1); } else if (sub_cmd == PWM_SET_DISABLE) { ret = pwm_set_enable(dev, channel, 0); - } else { - printf("PWM arguments missing\n"); - return CMD_RET_FAILURE; } if (ret) { -- cgit v1.2.3 From a70abcff5edb63ee62976ddfe881a8496e540d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Tue, 9 Feb 2021 21:23:47 +0100 Subject: cmd: pinmux: depend on PINCTRL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pinmux command uses functions pinctrl_get_pin_*(), which are missing if PINCTRL config option is disabled. Signed-off-by: Marek BehĂșn Cc: Simon Glass Cc: Tom Rini Reviewed-by: Simon Glass --- cmd/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 928a2a0a2de..4defbd9cf9c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1188,6 +1188,7 @@ config CMD_PCI config CMD_PINMUX bool "pinmux - show pins muxing" + depends on PINCTRL default y if PINCTRL help Parse all available pin-controllers and show pins muxing. This -- cgit v1.2.3