* [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get
@ 2026-02-18 20:52 Dmitry Torokhov
2026-02-18 23:40 ` David Lechner
2026-02-19 10:48 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2026-02-18 20:52 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Linus Walleij,
Bartosz Golaszewski, linux-iio, linux-kernel, linux-gpio
The GPIO get callback is expected to return 0 or 1 (or a negative error
code). Ensure that the value returned by ti_ads7950_get() for output
pins is normalized to the [0, 1] range.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/iio/adc/ti-ads7950.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index bbe1ce577789..0c4db18ec4d7 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -433,7 +433,7 @@ static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
/* If set as output, return the output */
if (st->gpio_cmd_settings_bitmask & BIT(offset)) {
- ret = st->cmd_settings_bitmask & BIT(offset);
+ ret = !!(st->cmd_settings_bitmask & BIT(offset));
goto out;
}
--
2.53.0.335.g19a08e0c02-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get
2026-02-18 20:52 [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get Dmitry Torokhov
@ 2026-02-18 23:40 ` David Lechner
2026-02-19 10:48 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: David Lechner @ 2026-02-18 23:40 UTC (permalink / raw)
To: Dmitry Torokhov, Jonathan Cameron
Cc: Nuno Sá, Andy Shevchenko, Linus Walleij, Bartosz Golaszewski,
linux-iio, linux-kernel, linux-gpio
On 2/18/26 2:52 PM, Dmitry Torokhov wrote:
> The GPIO get callback is expected to return 0 or 1 (or a negative error
> code). Ensure that the value returned by ti_ads7950_get() for output
> pins is normalized to the [0, 1] range.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/iio/adc/ti-ads7950.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
> index bbe1ce577789..0c4db18ec4d7 100644
> --- a/drivers/iio/adc/ti-ads7950.c
> +++ b/drivers/iio/adc/ti-ads7950.c
> @@ -433,7 +433,7 @@ static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
>
> /* If set as output, return the output */
> if (st->gpio_cmd_settings_bitmask & BIT(offset)) {
> - ret = st->cmd_settings_bitmask & BIT(offset);
> + ret = !!(st->cmd_settings_bitmask & BIT(offset));
ret = (st->cmd_settings_bitmask & BIT(offset)) ? 1 : 0;
Would be consistent with the style of the rest of the function (see below).
> goto out;
> }
>
There is actually another bug with the return value of this function:
ret = ((st->single_rx >> 12) & BIT(offset)) ? 1 : 0;
/* Revert back to original settings */
st->cmd_settings_bitmask &= ~TI_ADS7950_CR_GPIO_DATA;
st->single_tx = TI_ADS7950_MAN_CMD_SETTINGS(st);
ret = spi_sync(st->spi, &st->scan_single_msg);
if (ret)
goto out;
out:
mutex_unlock(&st->slock);
return ret;
}
When the gpio is an input, the function always returns 0 or error,
never 1 because ret gets written over.
It looks like we need to introduce an extra variable to fix that one.
If we make the new variable bool, then we don't have to mess with
`!!` or `? 1 : 0` to normalize it. The compiler will do it for us.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get
2026-02-18 20:52 [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get Dmitry Torokhov
2026-02-18 23:40 ` David Lechner
@ 2026-02-19 10:48 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-02-19 10:48 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Linus Walleij, Bartosz Golaszewski, linux-iio, linux-kernel,
linux-gpio
On Wed, 18 Feb 2026 21:52:44 +0100, Dmitry Torokhov
<dmitry.torokhov@gmail.com> said:
> The GPIO get callback is expected to return 0 or 1 (or a negative error
> code). Ensure that the value returned by ti_ads7950_get() for output
> pins is normalized to the [0, 1] range.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/iio/adc/ti-ads7950.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
> index bbe1ce577789..0c4db18ec4d7 100644
> --- a/drivers/iio/adc/ti-ads7950.c
> +++ b/drivers/iio/adc/ti-ads7950.c
> @@ -433,7 +433,7 @@ static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
>
> /* If set as output, return the output */
> if (st->gpio_cmd_settings_bitmask & BIT(offset)) {
> - ret = st->cmd_settings_bitmask & BIT(offset);
> + ret = !!(st->cmd_settings_bitmask & BIT(offset));
> goto out;
> }
>
> --
> 2.53.0.335.g19a08e0c02-goog
>
>
> --
> Dmitry
>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-19 10:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 20:52 [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get Dmitry Torokhov
2026-02-18 23:40 ` David Lechner
2026-02-19 10:48 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox