[PATCH 5/5] gpiolib: gpioinfo: add optional CONTROLLER command line argument

Sascha Hauer sha at pengutronix.de
Wed Sep 28 07:24:38 PDT 2022


On Wed, Sep 28, 2022 at 03:22:46PM +0200, Enrico Scholz wrote:
> Ahmad Fatoum <a.fatoum at pengutronix.de> writes:
> 
> >  static int do_gpiolib(int argc, char *argv[])
> >  {
> > +	if (argc == 1) {
> > +		dev = find_device(argv[1]);
> 
> 'gpioinfo' without arguments will crash because this calls
> 'find_device(NULL)'
> 
> | :/ gpioinfo 
> | BUG: failure at lib/string.c:226/strcmp()!
> | BUG!

I fixed it with the obvious change

Sascha

----------------------------8<--------------------------

>From 252c76cdf8c9d516589d72ac228ac0d19fcb2021 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Wed, 28 Sep 2022 16:20:48 +0200
Subject: [PATCH] gpiolib: Fix gpioinfo without args

Since a30ae2921a the gpioinfo command crashes when called without
arguments. Fix it by using argv[1] when it actually exists, not when
it doesn't exist.

Fixes: a30ae2921a ("gpiolib: gpioinfo: add optional CONTROLLER command line argument")
Reported-by: Enrico Scholz <enrico.scholz at sigma-chemnitz.de>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 7f20709035..2503262d65 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -681,7 +681,7 @@ static int do_gpiolib(int argc, char *argv[])
 	if (argc > 2)
 		return COMMAND_ERROR_USAGE;
 
-	if (argc == 1) {
+	if (argc > 1) {
 		struct device_d *dev;
 
 		dev = find_device(argv[1]);
-- 
2.30.2

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list