[PATCH 06/11] commands: gpio: Use kstrtoint() instead of simple_strtoul()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 commands/gpio.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/commands/gpio.c b/commands/gpio.c
index 5a28493d1..3a2b8624f 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[])
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux