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>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"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 3/4] iio: adc: ti-ads7950: switch to using guard() notation
Date: Mon, 23 Feb 2026 10:31:12 -0600	[thread overview]
Message-ID: <022c6472-0f7f-4c56-8ba7-7f9690e8a625@baylibre.com> (raw)
In-Reply-To: <aZt1ypf6msZxc2U1@google.com>

On 2/22/26 3:37 PM, Dmitry Torokhov wrote:
> On Sat, Feb 21, 2026 at 11:34:33AM -0600, David Lechner wrote:
>> On 2/18/26 8:29 PM, Dmitry Torokhov wrote:
>>> +	scoped_guard(mutex, &st->slock) {
>>> +		error = spi_sync(st->spi, &st->ring_msg);
>>> +		if (error)
>>> +			break;
>>
>> I'm not a fan of scoped_guard() because of the hidden for loop in it.
>> It hides the fact that the break; is breaking out of that for loop.
>>
>> It would be more clear/obvious written as:
>>
>> 	do {
>> 		guard(mutex)(&st->slock);
>>
>> 		ret = spi_sync(st->spi, &st->ring_msg);
>> 		if (ret)
>> 			break;
>>
>> 		iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2],
>> 						   iio_get_time_ns(indio_dev));
>> 	} while (0);
> 
> OK.
> 
> I could also make it
> 
> 	scoped_guard(mutex, &st->slock) {
> 		ret = spi_sync(st->spi, &st->ring_msg);
> 		if (!ret)
> 			iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2],
> 							   iio_get_time_ns(indio_dev));
> 	}

This is OK.

> 
> to avoid using "break".
> 
> I think you will find that scoped_guard() will gain the foothold in the
> kernel so having implementation that does not follow common pattern
> might not be the best option.

In general, I agree with this idea.

In this case, the common pattern unfortunately leads to common bugs.
Since we were discussing this, I audited the kernel and found and 
reported 3 unintentional mistakes with break/continue when scoped_guard()
was introduced. And I have caught more in reviews before they made it
into the kernel.

So I make an exception here to thinking that the common pattern is best.

> 
>>>  
>>>  	/* If set as output, return the output */
>>>  	if (st->gpio_cmd_settings_bitmask & BIT(offset)) {
>>>  		state = st->cmd_settings_bitmask & BIT(offset);
>>> -		goto out;
>>> +		return state;
>>
>> This can return directly instead of using local variable.
> 
> This will require the explicitly normalizing, which we avoided by
> introducing "bool state" to begin with...
> 
>>>  
>>>  	st->single_tx = TI_ADS7950_GPIO_CMD_SETTINGS(st);
>>> -	ret = spi_sync(st->spi, &st->scan_single_msg);
>>> +	error = spi_sync(st->spi, &st->scan_single_msg);
>>
>> Can just return directly here now.
> 
> I think there is benefit in explicitly calling out the error paths and
> explicitly return 0 on success. It removes the doubt whether a function
> can return positive value on success.

In the IIO subsystem, the direct return is preferred (maintainer and
other reviewers frequently request this).

> 
> Thanks.
> 


  reply	other threads:[~2026-02-23 16:31 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
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 [this message]
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=022c6472-0f7f-4c56-8ba7-7f9690e8a625@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®