mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH v2 2/4] iio: adc: ti-ads7950: do not clobber gpio state in ti_ads7950_get()
Date: Sat, 21 Feb 2026 11:21:42 -0600	[thread overview]
Message-ID: <6c8809a2-04fd-4044-a07e-8b74c964ead6@baylibre.com> (raw)
In-Reply-To: <20260219022929.3558081-3-dmitry.torokhov@gmail.com>

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@baylibre.com>

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@gmail.com>
> ---
>  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,


  parent reply	other threads:[~2026-02-21 17:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19  2:29 [PATCH v2 0/4] ti-ads7950: fix gpio handling and facelift Dmitry Torokhov
2026-02-19  2:29 ` [PATCH v2 1/4] iio: adc: ti-ads7950: normalize return value of gpio_get Dmitry Torokhov
2026-02-19  7:52   ` Andy Shevchenko
2026-02-19  9:17   ` Bartosz Golaszewski
2026-02-19 18:25   ` Linus Walleij
2026-02-22 14:03   ` Jonathan Cameron
2026-02-22 21:22     ` Dmitry Torokhov
2026-02-19  2:29 ` [PATCH v2 2/4] iio: adc: ti-ads7950: do not clobber gpio state in ti_ads7950_get() Dmitry Torokhov
2026-02-19  7:55   ` Andy Shevchenko
2026-02-21 17:21   ` David Lechner [this message]
2026-02-19  2:29 ` [PATCH v2 3/4] iio: adc: ti-ads7950: switch to using guard() notation Dmitry Torokhov
2026-02-19  7:51   ` Andy Shevchenko
2026-02-21 17:20     ` David Lechner
2026-02-22 21:31       ` Dmitry Torokhov
2026-02-23 16:35         ` David Lechner
2026-02-21 17:34   ` David Lechner
2026-02-22 21:37     ` Dmitry Torokhov
2026-02-23 16:31       ` David Lechner
2026-02-19  2:29 ` [PATCH v2 4/4] iio: adc: ti-ads7950: complete conversion to using managed resources Dmitry Torokhov
2026-02-19  7:59   ` Andy Shevchenko
2026-02-21  0:09     ` Dmitry Torokhov
2026-02-22 19:12       ` Andy Shevchenko
2026-02-23 20:52         ` Jonathan Cameron
2026-02-21 17:43   ` David Lechner
2026-02-22 14:09   ` Jonathan Cameron
2026-02-22 21:39     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c8809a2-04fd-4044-a07e-8b74c964ead6@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®