From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Lucas Ivars Cadima Ciziks <lucas@ciziks.com>,
lars@metafoo.de, Michael.Hennerich@analog.com,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
Felipe Ribeiro de Souza <felipers@usp.br>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: ad7280a: use cleanup helpers guard() and scoped_guard() for mutex locking
Date: Sun, 19 Apr 2026 18:25:55 +0100 [thread overview]
Message-ID: <20260419182555.44eb4e28@jic23-huawei> (raw)
In-Reply-To: <aeHpz7Ny2hP6Xj0U@ashevche-desk.local>
On Fri, 17 Apr 2026 11:05:35 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Apr 15, 2026 at 01:08:38PM -0300, Lucas Ivars Cadima Ciziks wrote:
> > Replace open-coded mutex_lock/unlock pairs with the cleanup-based
> > guard() and scoped_guard() helpers in ad7280a_write_thresh(),
> > ad7280_show_balance_timer(), ad7280_store_balance_sw(),
> > ad7280_store_balance_timer() and ad7280_read_raw().
> >
> > This removes the need for the err_unlock label and explicit
> > mutex_unlock() calls, as the lock is now automatically released
> > when the function returns or the guarded scope exits, regardless
> > of the exit path.
>
> ...
>
> > static ssize_t ad7280_show_balance_timer(struct iio_dev *indio_dev,
>
> > unsigned int msecs;
> > int ret;
> >
> > - mutex_lock(&st->lock);
> > + guard(mutex)(&st->lock);
>
> This will add some rather heavy operation into the critical section.
> Why do we need that? Please, use scoped_guard() in such cases.
>
Even better. Look at how ad7280_read_reg() is used and consider should the lock
actually be external to that?
There might be a strong enough consistency argument for scoped guard out here.
I haven't really looked at it closely.
> > ret = ad7280_read_reg(st, chan->address >> 8,
> > (chan->address & 0xFF) + AD7280A_CB1_TIMER_REG);
> > - mutex_unlock(&st->lock);
> >
> > if (ret < 0)
> > return ret;
>
prev parent reply other threads:[~2026-04-19 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 16:08 [PATCH v2] iio: adc: ad7280a: use cleanup helpers guard() and scoped_guard() for mutex locking Lucas Ivars Cadima Ciziks
2026-04-17 8:05 ` Andy Shevchenko
2026-04-19 17:25 ` Jonathan Cameron [this message]
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=20260419182555.44eb4e28@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=felipers@usp.br \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=lucas@ciziks.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