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

From: Dmitry Torokhov

Date: Wed Feb 18 2026 - 21:30:42 EST


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>
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);
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,
--
2.53.0.335.g19a08e0c02-goog