[U-Boot] [PATCH] gpio: return success if value is positiv

Currently we return the GPIO value directly as command exit code. In shell exit codes, 0 means success. Hence if a GPIO is one, we actually return a "failure". Fix this by returning SUCCESS if the value is positive.
This allows to implement scripts more naturally e.g.: if gpio input 47; then echo "Pressed"; else echo "Not pressed"; fi
Signed-off-by: Stefan Agner stefan@agner.ch --- Not sure if it is the right thing to do to change that, maybe there are a lot of users which rely on that output already?
It just feels a bit more natural to me when using the command in scripts...
-- Stefan
common/cmd_gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c index 65d6df4..ed735bd 100644 --- a/common/cmd_gpio.c +++ b/common/cmd_gpio.c @@ -208,7 +208,10 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (ret != -EBUSY) gpio_free(gpio);
- return value; + if (value) + return CMD_RET_SUCCESS; + else + return CMD_RET_FAILURE; }
U_BOOT_CMD(gpio, 4, 0, do_gpio,

On Fri, Oct 23, 2015 at 03:59:18PM -0700, Stefan Agner wrote:
Currently we return the GPIO value directly as command exit code. In shell exit codes, 0 means success. Hence if a GPIO is one, we actually return a "failure". Fix this by returning SUCCESS if the value is positive.
This allows to implement scripts more naturally e.g.: if gpio input 47; then echo "Pressed"; else echo "Not pressed"; fi
Signed-off-by: Stefan Agner stefan@agner.ch
Not sure if it is the right thing to do to change that, maybe there are a lot of users which rely on that output already?
It just feels a bit more natural to me when using the command in scripts...
My first reaction is, wait, we don't work like that today? I need to try the omap3_beagle gpio stuff out on my board again since there are users today that at first blush read like what you're saying doesn't work today, so I wonder if things broke by accident at some point in the (hopefully not too distant) past.
participants (2)
-
Stefan Agner
-
Tom Rini