shell: modules: devmem: use shell_strtoul
in cmd_dump
Switch from using direct `strtoul` calls to `shell_strtoul`. This change leverages the extensive error handling provided by `shell_strtoul`. Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit is contained in:
parent
27cbe0553c
commit
8fedee30ee
1 changed files with 7 additions and 6 deletions
|
@ -97,6 +97,7 @@ static int memory_dump(const struct shell *sh, mem_addr_t phys_addr, size_t size
|
||||||
static int cmd_dump(const struct shell *sh, size_t argc, char **argv)
|
static int cmd_dump(const struct shell *sh, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
int err = 0;
|
||||||
size_t size = -1;
|
size_t size = -1;
|
||||||
size_t width = 32;
|
size_t width = 32;
|
||||||
mem_addr_t addr = -1;
|
mem_addr_t addr = -1;
|
||||||
|
@ -108,22 +109,22 @@ static int cmd_dump(const struct shell *sh, size_t argc, char **argv)
|
||||||
while ((rv = getopt(argc, argv, "a:s:w:")) != -1) {
|
while ((rv = getopt(argc, argv, "a:s:w:")) != -1) {
|
||||||
switch (rv) {
|
switch (rv) {
|
||||||
case 'a':
|
case 'a':
|
||||||
addr = (mem_addr_t)strtoul(optarg, NULL, 16);
|
addr = (mem_addr_t)shell_strtoul(optarg, 16, &err);
|
||||||
if (addr == 0 && errno == EINVAL) {
|
if (err != 0) {
|
||||||
shell_error(sh, "invalid addr '%s'", optarg);
|
shell_error(sh, "invalid addr '%s'", optarg);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
size = (size_t)strtoul(optarg, NULL, 0);
|
size = (size_t)shell_strtoul(optarg, 0, &err);
|
||||||
if (size == 0 && errno == EINVAL) {
|
if (err != 0) {
|
||||||
shell_error(sh, "invalid size '%s'", optarg);
|
shell_error(sh, "invalid size '%s'", optarg);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
width = (size_t)strtoul(optarg, NULL, 0);
|
width = (size_t)shell_strtoul(optarg, 0, &err);
|
||||||
if (width == 0 && errno == EINVAL) {
|
if (err != 0) {
|
||||||
shell_error(sh, "invalid width '%s'", optarg);
|
shell_error(sh, "invalid width '%s'", optarg);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue