diff mbox series

cmd: spi: Judge the number of added parameters

Message ID 20221206092438.12290-1-chenzhipeng@eswincomputing.com
State Accepted
Commit c40e021b83d9db9aec736a0cb992fd84d2e63c02
Delegated to: Tom Rini
Headers show
Series cmd: spi: Judge the number of added parameters | expand

Commit Message

Zhipeng Chen Dec. 6, 2022, 9:24 a.m. UTC
When only sspi is entered, help information can be printed.

Signed-off-by: chenzhipeng <chenzhipeng@eswincomputing.com>
---
 cmd/spi.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Glass Dec. 7, 2022, 1:08 a.m. UTC | #1
On Wed, 7 Dec 2022 at 03:50, chenzhipeng <chenzhipeng@eswincomputing.com> wrote:
>
> When only sspi is entered, help information can be printed.
>
> Signed-off-by: chenzhipeng <chenzhipeng@eswincomputing.com>
> ---
>  cmd/spi.c | 3 +++
>  1 file changed, 3 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>



> diff --git a/cmd/spi.c b/cmd/spi.c
> index 454ebe37d7..f30018f33b 100644
> --- a/cmd/spi.c
> +++ b/cmd/spi.c
> @@ -112,6 +112,9 @@ int do_spi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>
>         if ((flag & CMD_FLAG_REPEAT) == 0)
>         {
> +               if (argc < 2)
> +                       return CMD_RET_USAGE;
> +
>                 if (argc >= 2) {
>                         mode = CONFIG_DEFAULT_SPI_MODE;
>                         bus = dectoul(argv[1], &cp);
> --
> 2.25.1
>
Tom Rini Jan. 13, 2023, 12:16 a.m. UTC | #2
On Tue, Dec 06, 2022 at 05:24:38PM +0800, chenzhipeng wrote:

> When only sspi is entered, help information can be printed.
> 
> Signed-off-by: chenzhipeng <chenzhipeng@eswincomputing.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/cmd/spi.c b/cmd/spi.c
index 454ebe37d7..f30018f33b 100644
--- a/cmd/spi.c
+++ b/cmd/spi.c
@@ -112,6 +112,9 @@  int do_spi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	if ((flag & CMD_FLAG_REPEAT) == 0)
 	{
+		if (argc < 2)
+			return CMD_RET_USAGE;
+
 		if (argc >= 2) {
 			mode = CONFIG_DEFAULT_SPI_MODE;
 			bus = dectoul(argv[1], &cp);