lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 26 Nov 2015 11:08:45 +0100
From:	Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@...i.com>
To:	<linux-gpio@...r.kernel.org>
CC:	<linux-kernel@...r.kernel.org>, <linus.walleij@...aro.org>,
	<gnurou@...il.com>, <jose.diazdegrenudepedro@...i.com>,
	<hector.palacios@...i.com>
Subject: [PATCH] gpiolib: return 0 or 1 in gpiod_get_value*() functions

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@...i.com>
Signed-off-by: Hector Palacios <hector.palacios@...i.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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ