Re: [PATCH v4 1/4] iio: adc: ti-ads7950: switch to using guard() notation

From: Dmitry Torokhov

Date: Mon Mar 30 2026 - 05:26:44 EST


On March 30, 2026 2:15:42 AM PDT, Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
>On Mon, 30 Mar 2026 00:47:06 +0200, Dmitry Torokhov
><dmitry.torokhov@xxxxxxxxx> said:
>> guard() notation allows early returns when encountering errors, making
>> control flow more obvious. Use it.
>>
>> Reviewed-by: David Lechner <dlechner@xxxxxxxxxxxx>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
>> ---
>> drivers/iio/adc/ti-ads7950.c | 83 +++++++++++++++++---------------------------
>> 1 file changed, 31 insertions(+), 52 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
>> index 028acd42741f..6e9ea9cc33bf 100644
>> --- a/drivers/iio/adc/ti-ads7950.c
>> +++ b/drivers/iio/adc/ti-ads7950.c
>> @@ -299,18 +299,19 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p)
>> struct ti_ads7950_state *st = iio_priv(indio_dev);
>> int ret;
>>
>> - mutex_lock(&st->slock);
>> - ret = spi_sync(st->spi, &st->ring_msg);
>> - if (ret < 0)
>> - goto out;
>> -
>> - iio_push_to_buffers_with_ts_unaligned(indio_dev, &st->rx_buf[2],
>> - sizeof(*st->rx_buf) *
>> - TI_ADS7950_MAX_CHAN,
>> - iio_get_time_ns(indio_dev));
>> -
>> -out:
>> - mutex_unlock(&st->slock);
>> + do {
>> + guard(mutex)(&st->slock);
>
>Am I missing something? Why isn't it just a:
>
> scoped_guard(mutex, &st->slock) {
> ...
> }

Maintainer's preference. It was a scoped guard in the first iteration.

Thanks.

--
Dmitry