diff options
author | Alexandre Courbot <acourbot@nvidia.com> | 2014-03-11 02:52:09 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-03-14 05:17:03 -0400 |
commit | 23600969ff137cf4c3bc9098f77e381de334e3f7 (patch) | |
tree | ad8bcad3af9b5635323b90cf0de346a1ee5db7c3 /drivers/gpio/gpiolib.c | |
parent | 6072b9dcf97870c9e840ad91862da7ff8ed680ee (diff) |
gpio: clamp returned values to the boolean range
Nothing prevents GPIO drivers from returning values outside the
boolean range, and as it turns out a few drivers are actually doing so.
These values were passed as-is to unsuspecting consumers and created
confusion.
This patch makes the internal _gpiod_get_raw_value() function return a
bool, effectively clamping the GPIO value to the boolean range no
matter what the driver does.
While we are at it, we also change the value parameter of
_gpiod_set_raw_value() to bool type before drivers start doing funny
things with it as well.
Another way to fix this would be to change the prototypes of the driver
interface to use bool directly, but this would require a huge
cross-systems patch so this simpler solution is preferred.
Changes since v1:
- Change local variable type to bool as well, use boolean values in
code
- Also change prototype of open drain/open source setting functions
since they are only called from _gpiod_set_raw_value()
This probably calls for a larger booleanization of gpiolib, but let's
keep that for a latter change - right now we need to address the issue
of non-boolean values returned by drivers.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 3707930e082e..584d2b465f84 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -2005,15 +2005,15 @@ EXPORT_SYMBOL_GPL(gpiod_is_active_low); | |||
2005 | * that the GPIO was actually requested. | 2005 | * that the GPIO was actually requested. |
2006 | */ | 2006 | */ |
2007 | 2007 | ||
2008 | static int _gpiod_get_raw_value(const struct gpio_desc *desc) | 2008 | static bool _gpiod_get_raw_value(const struct gpio_desc *desc) |
2009 | { | 2009 | { |
2010 | struct gpio_chip *chip; | 2010 | struct gpio_chip *chip; |
2011 | int value; | 2011 | bool value; |
2012 | int offset; | 2012 | int offset; |
2013 | 2013 | ||
2014 | chip = desc->chip; | 2014 | chip = desc->chip; |
2015 | offset = gpio_chip_hwgpio(desc); | 2015 | offset = gpio_chip_hwgpio(desc); |
2016 | value = chip->get ? chip->get(chip, offset) : 0; | 2016 | value = chip->get ? chip->get(chip, offset) : false; |
2017 | trace_gpio_value(desc_to_gpio(desc), 1, value); | 2017 | trace_gpio_value(desc_to_gpio(desc), 1, value); |
2018 | return value; | 2018 | return value; |
2019 | } | 2019 | } |
@@ -2069,7 +2069,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_value); | |||
2069 | * @desc: gpio descriptor whose state need to be set. | 2069 | * @desc: gpio descriptor whose state need to be set. |
2070 | * @value: Non-zero for setting it HIGH otherise it will set to LOW. | 2070 | * @value: Non-zero for setting it HIGH otherise it will set to LOW. |
2071 | */ | 2071 | */ |
2072 | static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value) | 2072 | static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) |
2073 | { | 2073 | { |
2074 | int err = 0; | 2074 | int err = 0; |
2075 | struct gpio_chip *chip = desc->chip; | 2075 | struct gpio_chip *chip = desc->chip; |
@@ -2096,7 +2096,7 @@ static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value) | |||
2096 | * @desc: gpio descriptor whose state need to be set. | 2096 | * @desc: gpio descriptor whose state need to be set. |
2097 | * @value: Non-zero for setting it HIGH otherise it will set to LOW. | 2097 | * @value: Non-zero for setting it HIGH otherise it will set to LOW. |
2098 | */ | 2098 | */ |
2099 | static void _gpio_set_open_source_value(struct gpio_desc *desc, int value) | 2099 | static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) |
2100 | { | 2100 | { |
2101 | int err = 0; | 2101 | int err = 0; |
2102 | struct gpio_chip *chip = desc->chip; | 2102 | struct gpio_chip *chip = desc->chip; |
@@ -2118,7 +2118,7 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, int value) | |||
2118 | __func__, err); | 2118 | __func__, err); |
2119 | } | 2119 | } |
2120 | 2120 | ||
2121 | static void _gpiod_set_raw_value(struct gpio_desc *desc, int value) | 2121 | static void _gpiod_set_raw_value(struct gpio_desc *desc, bool value) |
2122 | { | 2122 | { |
2123 | struct gpio_chip *chip; | 2123 | struct gpio_chip *chip; |
2124 | 2124 | ||