gpiolib: add checks and error message
cover gpiolib: add checks and error message
This patchseries adds additional trivial checks and error message.
[PATCH 1/3] gpiolib: gpio_request(): print message on error [PATCH 2/3] gpiolib: gpio_free: clear gpio's "label" field too [PATCH 3/3] gpiolib: gpiolib command: show label only for requested
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/3 gpiolib: gpio_request(): print message on error
Just copy gpiod_request() function logic from linux-v3.13-rc7.
--- drivers/gpio/gpiolib.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +17 -6
@@ -50,22 +50,33 @@ int gpio_request(unsigned gpio, const char *label)struct gpio_info *gi =gpio_to_desc (gpio);int ret; -if (!gi) -return -ENODEV ; +if (!gi) { + ret = -ENODEV ; + goto done; + } -if (gi->requested) -return -EBUSY ; +if (gi->requested) { + ret = -EBUSY ; + goto done; + } + + ret =0 ;if (gi->chip->ops->request) { ret = gi->chip->ops->request (gi->chip, gpio - gi->chip->base);if (ret) -return ret; + goto done; } gi->requested = true; gi->label =xstrdup (label); -return 0 ; +done: +if (ret) +pr_err ("_gpio_request: gpio-%d (%s) status %d\n" , + gpio, label ? :"?" , ret); + +return ret; }void gpio_free (unsigned gpio)
Signature · 7 lines
1.8.5.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/3 gpiolib: gpio_free: clear gpio's "label" field too
In reply to Antony PavlovIf an error occured during gpio_request_array() then we can get not requested gpio with nonempty garbage "label" field value. Afterward the "gpiolib" command can try to use this nonempty garbage value.
This patch prevents this error situation.
--- drivers/gpio/gpiolib.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib.c +1 -0
@@ -94,6 +94,7 @@ void gpio_free(unsigned gpio) gi->requested = false;free (gi->label); + gi->label =NULL ; }/**
Signature · 7 lines
1.8.5.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/3 gpiolib: gpiolib command: show label only for requested pins
In reply to Antony Pavlov--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
@@ -334,7 +334,7 @@ static int do_gpiolib(int argc, char *argv[])3 , (dir <0 ) ?"unk" : ((dir ==GPIOF_DIR_IN ) ?"in" :"out" ),3 , (val <0 ) ?"unk" : ((val ==0 ) ?"lo" :"hi" ),9 , gi->requested ?"true" :"false" , - gi->label ? gi->label : ""); + (gi->requested && gi->label) ? gi->label : ""); }return 0 ;
Signature · 7 lines
1.8.5.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 5 lines · Antony Pavlov
This patchseries adds additional trivial checks and error message.
[PATCH 1/3] gpiolib:
gpio_request(): print message on error [PATCH 2/3] gpiolib:gpio_free: clear gpio's "label" field too [PATCH 3/3] gpiolib: gpiolib command: show label only for requested
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox