Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1278131

[PATCH] gpiolib: return 0 or 1 in gpiod_get_value*() functions

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
Newsgroups linux.kernel
Subject [PATCH] gpiolib: return 0 or 1 in gpiod_get_value*() functions
Date Thu, 26 Nov 2015 11:20:01 +0100
Message-ID <qz1OF-3N3-5@gated-at.bofh.it> (permalink)
X-Original-To <linux-gpio@vger.kernel.org>
X-Greylist delayed 401 seconds by postgrey-1.27 at vger.kernel.org; Thu, 26 Nov 2015 05:15:38 EST
X-Env-Sender Jose.DiazdeGrenudePedro@digi.com
X-Msg-Ref server-11.tower-164.messagelabs.com!1448532533!2079962!1
X-Originating-IP [192.109.95.98]
X-Starscan-Version 7.19.2; banners=-,-,-
X-Viruschecked Checked
X-Mailer git-send-email 2.6.3
MIME-Version 1.0
Content-Type text/plain
X-Originating-IP [10.101.11.101]
X-Kse-Antispam-Interceptor-Info protection disabled
X-Kse-Antivirus-Interceptor-Info scan successful
X-Kse-Antivirus-Info Clean
X-Kse-Antispam-Interceptor-Info protection disabled
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 53
Organization linux.* mail to news gateway
X-Original-Cc <linux-kernel@vger.kernel.org>, <linus.walleij@linaro.org>, <gnurou@gmail.com>, <jose.diazdegrenudepedro@digi.com>, <hector.palacios@digi.com>
X-Original-Date Thu, 26 Nov 2015 11:08:45 +0100
X-Original-Message-ID <1448532525-12629-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1278131

Show key headers only | View raw


Commit 79a9becda894 moved the awareness of active low state
into the gpiod_get_value*() functions, but it only inverts the
GPIO's raw value when it is active low. If the GPIO is active
high, the gpiod_get_value*() functions return the raw value of
the register, which can be any positive value.

This patch does a double inversion when the GPIO is active high
to make sure either a 0 or 1 is returned by these functions.

Signed-off-by: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
---
 drivers/gpio/gpiolib.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 50c4922fe53a..20f472a25b55 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1981,9 +1981,9 @@ int gpiod_get_value(const struct gpio_desc *desc)
 
 	value = _gpiod_get_raw_value(desc);
 	if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
-		value = !value;
-
-	return value;
+		return !value;
+	else
+		return !!value
 }
 EXPORT_SYMBOL_GPL(gpiod_get_value);
 
@@ -2224,9 +2224,9 @@ int gpiod_get_value_cansleep(const struct gpio_desc *desc)
 
 	value = _gpiod_get_raw_value(desc);
 	if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
-		value = !value;
-
-	return value;
+		return !value;
+	else
+		return !!value;
 }
 EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep);
 
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] gpiolib: return 0 or 1 in gpiod_get_value*() functions Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com> - 2015-11-26 11:20 +0100

csiph-web