cmd: fix return code of 'sf erase'
If the offset or the size passed to the 'sf erase' command exceeds the size of the SPI flash displaying the command usage is not helpful. Return CMD_RET_FAILURE instead of CMD_RET_USAGE. Use the CMD_RET_* constants instead of 0, 1, -1. Simplify a logical expression in the final return statement. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Acked-by: Dhruva Gole <d-gole@ti.com> Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
This commit is contained in:
parent
8c8df67609
commit
ee0b0be204
1 changed files with 6 additions and 6 deletions
12
cmd/sf.c
12
cmd/sf.c
|
@ -343,27 +343,27 @@ static int do_spi_flash_erase(int argc, char *const argv[])
|
||||||
ulong size;
|
ulong size;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
return -1;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
|
if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
|
||||||
MTD_DEV_TYPE_NOR, flash->size))
|
MTD_DEV_TYPE_NOR, flash->size))
|
||||||
return -1;
|
return CMD_RET_FAILURE;
|
||||||
|
|
||||||
ret = sf_parse_len_arg(argv[2], &size);
|
ret = sf_parse_len_arg(argv[2], &size);
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
return -1;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
/* Consistency checking */
|
/* Consistency checking */
|
||||||
if (offset + size > flash->size) {
|
if (offset + size > flash->size) {
|
||||||
printf("ERROR: attempting %s past flash size (%#x)\n",
|
printf("ERROR: attempting %s past flash size (%#x)\n",
|
||||||
argv[0], flash->size);
|
argv[0], flash->size);
|
||||||
return 1;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash->flash_is_unlocked &&
|
if (flash->flash_is_unlocked &&
|
||||||
!flash->flash_is_unlocked(flash, offset, len)) {
|
!flash->flash_is_unlocked(flash, offset, len)) {
|
||||||
printf("ERROR: flash area is locked\n");
|
printf("ERROR: flash area is locked\n");
|
||||||
return 1;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = spi_flash_erase(flash, offset, size);
|
ret = spi_flash_erase(flash, offset, size);
|
||||||
|
@ -373,7 +373,7 @@ static int do_spi_flash_erase(int argc, char *const argv[])
|
||||||
else
|
else
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
|
|
||||||
return ret == 0 ? 0 : 1;
|
return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_spi_protect(int argc, char *const argv[])
|
static int do_spi_protect(int argc, char *const argv[])
|
||||||
|
|
Loading…
Reference in a new issue