diff mbox series

[U-Boot,3/4] cmd: mtd: Don't use with negative return codes for shell commands

Message ID 20180806151253.31205-3-sr@denx.de
State Superseded
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot,1/4] spi: spi-mem: Add optional half-duplex SPI transfer mode | expand

Commit Message

Stefan Roese Aug. 6, 2018, 3:12 p.m. UTC
When negative return codes are used in commands (do_foo()), the shell
prints these messages:

exit not allowed from main input shell.

Change the return codes in the new mtd commands to use only positive
values and these annoying warnings are gone.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Jagan Teki <jagan@openedev.com>
---
 cmd/mtd.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Boris Brezillon Aug. 6, 2018, 8:38 p.m. UTC | #1
On Mon,  6 Aug 2018 17:12:52 +0200
Stefan Roese <sr@denx.de> wrote:

> When negative return codes are used in commands (do_foo()), the shell
> prints these messages:
> 
> exit not allowed from main input shell.
> 
> Change the return codes in the new mtd commands to use only positive
> values and these annoying warnings are gone.
> 
> Signed-off-by: Stefan Roese <sr@denx.de>
> Cc: Miquel Raynal <miquel.raynal@bootlin.com>
> Cc: Boris Brezillon <boris.brezillon@bootlin.com>
> Cc: Jagan Teki <jagan@openedev.com>
> ---
>  cmd/mtd.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> index 221b12500f..38a89736cf 100644
> --- a/cmd/mtd.c
> +++ b/cmd/mtd.c
> @@ -188,7 +188,7 @@ static int do_mtd_list(void)
>  
>  	if (!dev_nb) {
>  		printf("No MTD device found\n");
> -		return -EINVAL;
> +		return EINVAL;

How about using CMD_RET_FAILURE for all errors?
Stefan Roese Aug. 7, 2018, 5:07 a.m. UTC | #2
Hi Boris,

On 06.08.2018 22:38, Boris Brezillon wrote:
> On Mon,  6 Aug 2018 17:12:52 +0200
> Stefan Roese <sr@denx.de> wrote:
> 
>> When negative return codes are used in commands (do_foo()), the shell
>> prints these messages:
>>
>> exit not allowed from main input shell.
>>
>> Change the return codes in the new mtd commands to use only positive
>> values and these annoying warnings are gone.
>>
>> Signed-off-by: Stefan Roese <sr@denx.de>
>> Cc: Miquel Raynal <miquel.raynal@bootlin.com>
>> Cc: Boris Brezillon <boris.brezillon@bootlin.com>
>> Cc: Jagan Teki <jagan@openedev.com>
>> ---
>>   cmd/mtd.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/cmd/mtd.c b/cmd/mtd.c
>> index 221b12500f..38a89736cf 100644
>> --- a/cmd/mtd.c
>> +++ b/cmd/mtd.c
>> @@ -188,7 +188,7 @@ static int do_mtd_list(void)
>>   
>>   	if (!dev_nb) {
>>   		printf("No MTD device found\n");
>> -		return -EINVAL;
>> +		return EINVAL;
> 
> How about using CMD_RET_FAILURE for all errors?

Good idea, thanks. Will change in v2.

Thanks,
Stefan
diff mbox series

Patch

diff --git a/cmd/mtd.c b/cmd/mtd.c
index 221b12500f..38a89736cf 100644
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -188,7 +188,7 @@  static int do_mtd_list(void)
 
 	if (!dev_nb) {
 		printf("No MTD device found\n");
-		return -EINVAL;
+		return EINVAL;
 	}
 
 	return 0;
@@ -269,13 +269,13 @@  static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (mtd_is_aligned_with_min_io_size(mtd, off)) {
 			printf("Offset not aligned with a page (0x%x)\n",
 			       mtd->writesize);
-			return -EINVAL;
+			return EINVAL;
 		}
 
 		if (mtd_is_aligned_with_min_io_size(mtd, len)) {
 			printf("Size not a multiple of a page (0x%x)\n",
 			       mtd->writesize);
-			return -EINVAL;
+			return EINVAL;
 		}
 
 		if (dump)
@@ -285,7 +285,7 @@  static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 		if (!buf) {
 			printf("Could not map/allocate the user buffer\n");
-			return -ENOMEM;
+			return ENOMEM;
 		}
 
 		printf("%s %lldB (%d page(s)) at offset 0x%08llx%s%s\n",
@@ -306,7 +306,7 @@  static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (ret) {
 			printf("%s on %s failed with error %d\n",
 			       read ? "Read" : "Write", mtd->name, ret);
-			return ret;
+			return -ret;
 		}
 
 		if (dump) {
@@ -346,13 +346,13 @@  static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (mtd_is_aligned_with_block_size(mtd, off)) {
 			printf("Offset not aligned with a block (0x%x)\n",
 			       mtd->erasesize);
-			return -EINVAL;
+			return EINVAL;
 		}
 
 		if (mtd_is_aligned_with_block_size(mtd, len)) {
 			printf("Size not a multiple of a block (0x%x)\n",
 			       mtd->erasesize);
-			return -EINVAL;
+			return EINVAL;
 		}
 
 		erase_op.mtd = mtd;