From 05a4b7d4b1b56af927d703e3667e1c7868bab1d4 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 26 Oct 2018 18:31:52 -0700 Subject: 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 Signed-off-by: Sascha Hauer --- commands/gpio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'commands') diff --git a/commands/gpio.c b/commands/gpio.c index 5a28493d1c..3a2b8624f4 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[]) -- cgit v1.2.3