* [PATCH 08/54] gpio: lpc32xx: Be sure to clamp return value
@ 2015-12-22 14:13 Linus Walleij
2015-12-28 4:11 ` Bjorn Andersson
0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2015-12-22 14:13 UTC (permalink / raw)
To: linux-gpio, Roland Stigge; +Cc: Linus Walleij, Vladimir Zapolskiy
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.
Cc: Roland Stigge <stigge@antcom.de>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/gpio/gpio-lpc32xx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c
index 47e2dde63734..e888b5fcd236 100644
--- a/drivers/gpio/gpio-lpc32xx.c
+++ b/drivers/gpio/gpio-lpc32xx.c
@@ -288,21 +288,21 @@ static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin)
{
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
- return __get_gpio_state_p012(group, pin);
+ return !!__get_gpio_state_p012(group, pin);
}
static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin)
{
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
- return __get_gpio_state_p3(group, pin);
+ return !!__get_gpio_state_p3(group, pin);
}
static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin)
{
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
- return __get_gpi_state_p3(group, pin);
+ return !!__get_gpi_state_p3(group, pin);
}
static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
@@ -364,7 +364,7 @@ static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin)
{
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
- return __get_gpo_state_p3(group, pin);
+ return !!__get_gpo_state_p3(group, pin);
}
static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin)
--
2.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 08/54] gpio: lpc32xx: Be sure to clamp return value
2015-12-22 14:13 [PATCH 08/54] gpio: lpc32xx: Be sure to clamp return value Linus Walleij
@ 2015-12-28 4:11 ` Bjorn Andersson
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Andersson @ 2015-12-28 4:11 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, Roland Stigge, Vladimir Zapolskiy
On Tue 22 Dec 06:13 PST 2015, Linus Walleij wrote:
> 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.
>
> Cc: Roland Stigge <stigge@antcom.de>
> Cc: Vladimir Zapolskiy <vz@mleia.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> drivers/gpio/gpio-lpc32xx.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c
> index 47e2dde63734..e888b5fcd236 100644
> --- a/drivers/gpio/gpio-lpc32xx.c
> +++ b/drivers/gpio/gpio-lpc32xx.c
> @@ -288,21 +288,21 @@ static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin)
> {
> struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
>
> - return __get_gpio_state_p012(group, pin);
> + return !!__get_gpio_state_p012(group, pin);
> }
>
> static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin)
> {
> struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
>
> - return __get_gpio_state_p3(group, pin);
> + return !!__get_gpio_state_p3(group, pin);
> }
>
> static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin)
> {
> struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
>
> - return __get_gpi_state_p3(group, pin);
> + return !!__get_gpi_state_p3(group, pin);
> }
>
> static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
> @@ -364,7 +364,7 @@ static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin)
> {
> struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
>
> - return __get_gpo_state_p3(group, pin);
> + return !!__get_gpo_state_p3(group, pin);
> }
>
> static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin)
All of these ends with a "& 1"-operation, so this patch is not needed.
Regards,
Bjorn
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-28 4:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-22 14:13 [PATCH 08/54] gpio: lpc32xx: Be sure to clamp return value Linus Walleij
2015-12-28 4:11 ` Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).