Skip to contentSkip to conversation

gpio: return success if value is positiv

PATCH New Stefan Agner 2 participants 2 messages Oct 23, 2015 – Oct 24, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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

---
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(-)
common/cmd_gpio.c +4 -1
index 65d6df4..ed735bd 100644
@@ -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,
Signature · 1 line
2.6.2
#1 lore raw

PATCH 1/1 gpio: return success if value is positiv

Quoted 8 lines · Stefan Agner

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

Quoted 7 lines

---
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.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151023/e18405b5/attachment.sig>