summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-26 18:31:52 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-29 09:10:38 +0100
commit05a4b7d4b1b56af927d703e3667e1c7868bab1d4 (patch)
tree0edf45301beb19c2cdfd6b79d219d0216a6169fe
parent4f3713adb0bc973122a977205a305813b38f63ba (diff)
downloadbarebox-05a4b7d4b1b56af927d703e3667e1c7868bab1d4.tar.gz
commands: gpio: Use kstrtoint() instead of simple_strtoul()
Use kstrtoint() instead of simple_strtoul() in order to properly handle invalid arguments. Current code using simple_strtoul() results in following: barebox@ZII RDU2 Board:/ gpio_get_value foo barebox@ZII RDU2 Board:/ echo $? 0 whereas with this patch we get: barebox@ZII RDU2 Board:/ gpio_get_value foo gpio_get_value: Invalid argument Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/gpio.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/commands/gpio.c b/commands/gpio.c
index 5a28493..3a2b862 100644
--- a/commands/gpio.c
+++ b/commands/gpio.c
@@ -20,16 +20,19 @@ static int get_gpio_and_value(int argc, char *argv[],
int *gpio, int *value)
{
const int count = value ? 3 : 2;
+ int ret;
if (argc < count)
return COMMAND_ERROR_USAGE;
- *gpio = simple_strtoul(argv[1], NULL, 0);
+ ret = kstrtoint(argv[1], 0, gpio);
+ if (ret < 0)
+ return ret;
if (value)
- *value = simple_strtoul(argv[2], NULL, 0);
+ ret = kstrtoint(argv[2], 0, value);
- return 0;
+ return ret;
}
static int do_gpio_get_value(int argc, char *argv[])