Re: [PATCH v2 2/4] iio: adc: ti-ads7950: do not clobber gpio state in ti_ads7950_get()

From: David Lechner

Date: Sat Feb 21 2026 - 12:22:28 EST


On 2/18/26 8:29 PM, Dmitry Torokhov wrote:
> GPIO state was inadvertently overwritten by the result of sip_sync,
> reuniting in ti_ads7950_get() only returning 0 as gpio state (or error).
>
> Fix this by introducing a separate variable to hold the state.
>
> Reported-by: David Lechner <dlechner@xxxxxxxxxxxx>

This should have a Fixes: tag since it is fixing a real bug.

Also, fixes should come first in the series.

> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
> ---
> drivers/iio/adc/ti-ads7950.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
> index b8cc39fc39fb..2a7d4a1d9fa9 100644
> --- a/drivers/iio/adc/ti-ads7950.c
> +++ b/drivers/iio/adc/ti-ads7950.c
> @@ -427,13 +427,14 @@ static int ti_ads7950_set(struct gpio_chip *chip, unsigned int offset,
> static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
> {
> struct ti_ads7950_state *st = gpiochip_get_data(chip);
> - int ret;
> + int ret = 0;
> + bool state;
>
> mutex_lock(&st->slock);
>
> /* If set as output, return the output */
> if (st->gpio_cmd_settings_bitmask & BIT(offset)) {
> - ret = (st->cmd_settings_bitmask & BIT(offset)) ? 1 : 0;
> + state = st->cmd_settings_bitmask & BIT(offset);

I agree it would be better to put...

ret = 0;

here.

> goto out;
> }
>
> @@ -444,7 +445,7 @@ static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
> if (ret)
> goto out;
>
> - ret = ((st->single_rx >> 12) & BIT(offset)) ? 1 : 0;
> + state = (st->single_rx >> 12) & BIT(offset);
>
> /* Revert back to original settings */
> st->cmd_settings_bitmask &= ~TI_ADS7950_CR_GPIO_DATA;
> @@ -456,7 +457,7 @@ static int ti_ads7950_get(struct gpio_chip *chip, unsigned int offset)
> out:
> mutex_unlock(&st->slock);
>
> - return ret;
> + return ret ?: state;> }
>
> static int ti_ads7950_get_direction(struct gpio_chip *chip,