From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Lucas Ivars Cadima Ciziks <lucas@ciziks.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
Matheus Giarola <matheusgiarola@usp.br>,
Felipe Ribeiro de Souza <felipers@usp.br>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v4] iio: adc: ad7280a: use cleanup helpers guard() and scoped_guard() for mutex locking
Date: Fri, 24 Apr 2026 12:42:08 +0300 [thread overview]
Message-ID: <aes68EaF7HkJn24T@ashevche-desk.local> (raw)
In-Reply-To: <20260423133322.13298-1-lucas@ciziks.com>
On Thu, Apr 23, 2026 at 10:26:48AM -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.
...
> switch (m) {
> - case IIO_CHAN_INFO_RAW:
> - mutex_lock(&st->lock);
> + case IIO_CHAN_INFO_RAW: {
> + guard(mutex)(&st->lock);
> +
> if (chan->address == AD7280A_ALL_CELLS)
> ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
> else
> ret = ad7280_read_channel(st, chan->address >> 8,
> chan->address & 0xFF);
> - mutex_unlock(&st->lock);
Same idea of splitting devaddr + ch variables can be made for this entire
switch-case...
> if (ret < 0)
> return ret;
> *val = ret;
>
> return IIO_VAL_INT;
> + }
> case IIO_CHAN_INFO_SCALE:
> if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6_REG)
...as I assume that would benefit this code as well.
Perhaps it should be done as preparatory patch.
> *val = 4000;
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-04-24 9:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 13:26 [PATCH v4] iio: adc: ad7280a: use cleanup helpers guard() and scoped_guard() for mutex locking Lucas Ivars Cadima Ciziks
2026-04-24 9:42 ` Andy Shevchenko [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=aes68EaF7HkJn24T@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=felipers@usp.br \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=lucas@ciziks.com \
--cc=matheusgiarola@usp.br \
--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