From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Guilherme Dias" <guilhermeabreu200105@usp.br>,
nish.malpani25@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, dlechner@baylibre.com,
nuno.sa@analog.com, andy@kernel.org,
"João Paulo Menezes Linaris" <jplinaris@usp.br>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock
Date: Fri, 24 Apr 2026 11:39:01 +0100 [thread overview]
Message-ID: <20260424113901.0508dbc2@jic23-huawei> (raw)
In-Reply-To: <aes2tzgfXbuD6ccQ@ashevche-desk.local>
On Fri, 24 Apr 2026 12:24:07 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Thu, Apr 23, 2026 at 07:37:51PM -0300, Guilherme Dias wrote:
> > Use guard(mutex) to automatically release the lock on scope exit,
> > simplifying the error handling path and removing the need for
> > explicit unlock and goto-based cleanup.
>
> ...
>
> > static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *val)
> > {
> > struct adxrs290_state *st = iio_priv(indio_dev);
> > - int ret = 0;
> > int temp;
> >
> > - mutex_lock(&st->lock);
> > + guard(mutex)(&st->lock);
>
> + blank line.
>
> We usually consider guard()() as not semantically linked to any code above
> or below
>
> > temp = spi_w8r16(st->spi, cmd);
> > - if (temp < 0) {
> > - ret = temp;
> > - goto err_unlock;
> > - }
> > + if (temp < 0)
> > + return temp;
> >
> > *val = sign_extend32(temp, 15);
> > -
> > -err_unlock:
> > - mutex_unlock(&st->lock);
> > - return ret;
> > + return 0;
> > }
>
> Ditto for the similar cases below.
>
> ...
>
> > static int adxrs290_set_mode(struct iio_dev *indio_dev, enum adxrs290_mode mode)
>
> > default:
> > ret = -EINVAL;
> > - goto out_unlock;
> > + return ret;
>
> Just return directly the given error code.
>
> ...
>
> > static irqreturn_t adxrs290_trigger_handler(int irq, void *p)
>
> > - mutex_lock(&st->lock);
> > + scoped_guard(mutex, &st->lock){
>
> No. Besides wrong style of this line, this has a very broken indentation now.
>
> > /* exercise a bulk data capture starting from reg DATAX0... */
> > ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels,
> > sizeof(st->buffer.channels));
> > - if (ret < 0)
> > - goto out_unlock_notify;
> > -
> > - iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
> > + if (ret >= 0)
No to this as well. Keep the error out of line. Which makes the use
of guard() here tricky. You could do a do { guard(); } while(0) loop so that
you can use break with out it being odd looking.
(I don't like breaks out of scoped_guard() because it's non obvious scoped
guard is actually a loop.
> > + iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
> > pf->timestamp);
> > + }
> >
> > -out_unlock_notify:
> > - mutex_unlock(&st->lock);
>
> > iio_trigger_notify_done(indio_dev->trig);
> > -
> > return IRQ_HANDLED;
>
> Stray change.
>
> > }
>
next prev parent reply other threads:[~2026-04-24 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 22:37 [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock Guilherme Dias
2026-04-24 9:24 ` Andy Shevchenko
2026-04-24 10:39 ` Jonathan Cameron [this message]
2026-04-27 22:04 ` Guilherme Dias
2026-04-28 8:01 ` Andy Shevchenko
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=20260424113901.0508dbc2@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=guilhermeabreu200105@usp.br \
--cc=jplinaris@usp.br \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=nish.malpani25@gmail.com \
--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