From 8fedee30ee4f4da6a69508ea031a44deec675cdf Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Sat, 24 Aug 2024 01:49:57 +0700 Subject: [PATCH] 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 --- subsys/shell/modules/devmem_service.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/subsys/shell/modules/devmem_service.c b/subsys/shell/modules/devmem_service.c index 7856ab8f862..3663e0a2cfa 100644 --- a/subsys/shell/modules/devmem_service.c +++ b/subsys/shell/modules/devmem_service.c @@ -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) { int rv; + int err = 0; size_t size = -1; size_t width = 32; 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) { switch (rv) { case 'a': - addr = (mem_addr_t)strtoul(optarg, NULL, 16); - if (addr == 0 && errno == EINVAL) { + addr = (mem_addr_t)shell_strtoul(optarg, 16, &err); + if (err != 0) { shell_error(sh, "invalid addr '%s'", optarg); return -EINVAL; } break; case 's': - size = (size_t)strtoul(optarg, NULL, 0); - if (size == 0 && errno == EINVAL) { + size = (size_t)shell_strtoul(optarg, 0, &err); + if (err != 0) { shell_error(sh, "invalid size '%s'", optarg); return -EINVAL; } break; case 'w': - width = (size_t)strtoul(optarg, NULL, 0); - if (width == 0 && errno == EINVAL) { + width = (size_t)shell_strtoul(optarg, 0, &err); + if (err != 0) { shell_error(sh, "invalid width '%s'", optarg); return -EINVAL; }