summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-02-14 11:33:35 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-02-14 11:40:25 +0100
commitf246b4079c746f80e29b07252c546d37a359105f (patch)
treeb07f7db09c3cce1cb6aa2cae6eeea14eef093b67 /commands
parente43eed6606e44574d665b3338b701da1035c504e (diff)
downloadbarebox-f246b4079c746f80e29b07252c546d37a359105f.tar.gz
i2c_probe command: Use kstrtoint
Use kstrtoint rather than simple_strtoul to catch erroneous input like "i2c1" which previously was silently interpreted as "0". Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/i2c.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/commands/i2c.c b/commands/i2c.c
index 77d65e3..77a8f7f 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -45,17 +45,37 @@ static int do_i2c_probe(int argc, char *argv[])
{
struct i2c_adapter *adapter = NULL;
int startaddr = 4, stopaddr = 0x77;
+ int ret;
if (argc > 1) {
- adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
+ int busnum;
+
+ ret = kstrtoint(argv[1], 0, &busnum);
+ if (ret) {
+ printf("Cannot parse \"%s\" as a number\n", argv[1]);
+ return ret;
+ }
+
+ adapter = i2c_get_adapter(busnum);
if (!adapter)
return -ENODEV;
}
- if (argc > 2)
- startaddr = simple_strtol(argv[2], NULL, 0);
- if (argc > 3)
- stopaddr = simple_strtol(argv[3], NULL, 0);
+ if (argc > 2) {
+ ret = kstrtoint(argv[2], 0, &startaddr);
+ if (ret) {
+ printf("Cannot parse \"%s\" as a number\n", argv[1]);
+ return ret;
+ }
+ }
+
+ if (argc > 3) {
+ ret = kstrtoint(argv[3], 0, &stopaddr);
+ if (ret) {
+ printf("Cannot parse \"%s\" as a number\n", argv[1]);
+ return ret;
+ }
+ }
if (stopaddr > 0x7f)
stopaddr = 0x7f;