Re: [PATCH] iio: adc: ti-ads7950: normalize return value of gpio_get

From: David Lechner

Date: Wed Feb 18 2026 - 18:40:17 EST


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@xxxxxxxxx>
> ---
> 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.