* [PATCH 1/3] gpiolib: gpio_request(): print message on error
2014-01-09 17:58 [PATCH 0/3] gpiolib: add checks and error message Antony Pavlov
@ 2014-01-09 17:58 ` Antony Pavlov
2014-01-09 17:58 ` [PATCH 2/3] gpiolib: gpio_free: clear gpio's "label" field too Antony Pavlov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2014-01-09 17:58 UTC (permalink / raw)
To: barebox
Just copy gpiod_request() function logic from linux-v3.13-rc7.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/gpio/gpiolib.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cafef90..b7430b0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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)
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] gpiolib: gpio_free: clear gpio's "label" field too
2014-01-09 17:58 [PATCH 0/3] gpiolib: add checks and error message Antony Pavlov
2014-01-09 17:58 ` [PATCH 1/3] gpiolib: gpio_request(): print message on error Antony Pavlov
@ 2014-01-09 17:58 ` Antony Pavlov
2014-01-09 17:58 ` [PATCH 3/3] gpiolib: gpiolib command: show label only for requested pins Antony Pavlov
2014-01-10 9:10 ` [PATCH 0/3] gpiolib: add checks and error message Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2014-01-09 17:58 UTC (permalink / raw)
To: barebox
If 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.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/gpio/gpiolib.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b7430b0..5f13d5f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -94,6 +94,7 @@ void gpio_free(unsigned gpio)
gi->requested = false;
free(gi->label);
+ gi->label = NULL;
}
/**
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] gpiolib: gpiolib command: show label only for requested pins
2014-01-09 17:58 [PATCH 0/3] gpiolib: add checks and error message Antony Pavlov
2014-01-09 17:58 ` [PATCH 1/3] gpiolib: gpio_request(): print message on error Antony Pavlov
2014-01-09 17:58 ` [PATCH 2/3] gpiolib: gpio_free: clear gpio's "label" field too Antony Pavlov
@ 2014-01-09 17:58 ` Antony Pavlov
2014-01-10 9:10 ` [PATCH 0/3] gpiolib: add checks and error message Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2014-01-09 17:58 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
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 5f13d5f..193c36c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] gpiolib: add checks and error message
2014-01-09 17:58 [PATCH 0/3] gpiolib: add checks and error message Antony Pavlov
` (2 preceding siblings ...)
2014-01-09 17:58 ` [PATCH 3/3] gpiolib: gpiolib command: show label only for requested pins Antony Pavlov
@ 2014-01-10 9:10 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-01-10 9:10 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Thu, Jan 09, 2014 at 09:58:36PM +0400, Antony Pavlov wrote:
> 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
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread