Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754067AbbK3Ran (ORCPT ); Mon, 30 Nov 2015 12:30:43 -0500 Received: from mail1.bemta12.messagelabs.com ([216.82.251.3]:19267 "EHLO mail1.bemta12.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752541AbbK3Ral (ORCPT ); Mon, 30 Nov 2015 12:30:41 -0500 X-Env-Sender: Jose.DiazdeGrenudePedro@digi.com X-Msg-Ref: server-15.tower-153.messagelabs.com!1448904637!2799874!2 X-Originating-IP: [192.109.95.98] X-StarScan-Received: X-StarScan-Version: 7.19.2; banners=-,-,- X-VirusChecked: Checked From: Jose Diaz de Grenu de Pedro To: CC: , , , , Subject: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions Date: Mon, 30 Nov 2015 18:30:31 +0100 Message-ID: <1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com> 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: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1692 Lines: 56 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 0 or 1 is returned by these functions. Signed-off-by: Jose Diaz de Grenu de Pedro Signed-off-by: Hector Palacios --- change in v2: - add missing semicolon --- 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..bd96f0457ba8 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/