diff mbox

[13/54] gpio: pcf857x: Be sure to clamp return value

Message ID 1450794009-22885-1-git-send-email-linus.walleij@linaro.org
State Accepted
Commit 40f805806dfb761650080ee008aeb96c012a0e03
Headers show

Commit Message

Linus Walleij Dec. 22, 2015, 2:20 p.m. UTC
As we want gpio_chip .get() calls to be able to return negative
error codes and propagate to drivers, we need to go over all
drivers and make sure their return values are clamped to [0,1].
We do this by using the ret = !!(val) design pattern.

Also start returning the error code if something fails, as the
end of the series augment the core to support this.

Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: George Cherian <george.cherian@ti.com>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/gpio/gpio-pcf857x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.4.3

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

Comments

Linus Walleij Jan. 1, 2016, 5:06 p.m. UTC | #1
On Sun, Dec 27, 2015 at 8:47 AM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:

> Would something like the following make sense ?

>

>         value = chip->get ? chip->get(chip, offset) : -EIO;

>         value = IS_ERR_VALUE(value) ? value : !!value;


Yeah that makes sense, I didn't think about using IS_ERR_VALUE()
to mitigate the situation.

Patches welcome :)

> Granted, GPIO drivers would still need to make sure that the value they return

> from register reads don't get considered as an error code, but any val & (1 <<

> offset) would be fine, which is the most common case.

>

> If you still think that patching all GPIO drivers is better I won't oppose to

> that.


I have already patches all the drivers with this problem, merged the
larger part of it and will merge the remainders for v4.6. The above is
still more elegant than the code we have so I'd take it to put some
nice robustness icing on top...

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index bf511c0efa48..f64380a7d004 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -154,7 +154,7 @@  static int pcf857x_get(struct gpio_chip *chip, unsigned offset)
 	int		value;
 
 	value = gpio->read(gpio->client);
-	return (value < 0) ? 0 : (value & (1 << offset));
+	return (value < 0) ? value : !!(value & (1 << offset));
 }
 
 static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value)