Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753874AbbK3UFx (ORCPT ); Mon, 30 Nov 2015 15:05:53 -0500 Received: from mail-lf0-f48.google.com ([209.85.215.48]:34013 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237AbbK3UFv (ORCPT ); Mon, 30 Nov 2015 15:05:51 -0500 MIME-Version: 1.0 In-Reply-To: <1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com> References: <1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com> Date: Mon, 30 Nov 2015 12:05:49 -0800 Message-ID: Subject: Re: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions From: Bjorn Andersson To: Jose Diaz de Grenu de Pedro Cc: "linux-gpio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linus Walleij , Alexandre Courbot , hector.palacios@digi.com Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1791 Lines: 50 On Mon, Nov 30, 2015 at 9:30 AM, Jose Diaz de Grenu de Pedro wrote: > 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); On linux-next (at least) _gpiod_get_raw_value() returns the following value: value = value < 0 ? value : !!value; So this should already be negative errno, 0 or 1. Regards, Bjorn -- 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/