Skip to content

Commit

Permalink
shell: modules: devmem: use shell_strtoul in cmd_dump
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ndrs-pst authored and kartben committed Dec 13, 2024
1 parent 27cbe05 commit 8fedee3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions subsys/shell/modules/devmem_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 8fedee3

Please sign in to comment.