From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Felipe Ribeiro de Souza <felipers@ime.usp.br>,
paul@crapouillou.net, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, Lucas Ivars Cadima Ciziks <lucas@ciziks.com>,
linux-mips@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation
Date: Sun, 19 Apr 2026 18:21:40 +0100 [thread overview]
Message-ID: <20260419182140.725830ab@jic23-huawei> (raw)
In-Reply-To: <aeHo7NFgvWe_3kPQ@ashevche-desk.local>
On Fri, 17 Apr 2026 11:01:48 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Apr 15, 2026 at 10:18:11PM -0300, Felipe Ribeiro de Souza wrote:
> > Replace mutex_lock(&lock) and mutex_unlock(&lock) calls with
> > guard(mutex)(&lock) in functions ingenic_adc_set_adcmd,
> > ingenic_adc_set_config, ingenic_adc_enable, ingenic_adc_capture
> > and ingenic_adc_read_chan_info_raw.
>
> We refer to the functions as func().
>
> > This removes the need to call the unlock function, as the lock is
> > automatically released when the function return or the scope exits
> > for any other case.
>
> ...
>
> > #include <linux/of.h>
> > #include <linux/platform_device.h>
> > #include <linux/property.h>
> > +#include <linux/cleanup.h>
>
> Preserve ordering.
>
> ...
>
> > /* We cannot sample the aux channels in parallel. */
> > - mutex_lock(&adc->aux_lock);
> > + guard(mutex)(&adc->lock);
>
> ...
>
> > ret = IIO_VAL_INT;
> > out:
Holding the lock a bit longer might be fine, but please go read the
comments in cleanup.h. The short version is don't combine use
of guard() with any gotos in the same function.
It's too high risk given different compiler behaviour and the chance of
code getting reorganized in the future
I wonder if anyone would be interested in applying ACQUIRE() and ACQUIRE_ERR()
to clock management. Might be worth seeing if that is of interest and general
enough as then you could handle the clk_disable() as well.
> > - mutex_unlock(&adc->aux_lock);
> > clk_disable(adc->clk);
>
> Not sure about this. At bare minimum you should elaborate on this change in the
> commit message.
>
> > return ret;
>
prev parent reply other threads:[~2026-04-19 17:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 1:18 [PATCH] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation Felipe Ribeiro de Souza
2026-04-16 10:08 ` Paul Cercueil
2026-04-17 5:18 ` Rong Zhang
2026-04-17 8:01 ` Andy Shevchenko
2026-04-19 17:21 ` 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=20260419182140.725830ab@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=felipers@ime.usp.br \
--cc=linux-iio@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=lucas@ciziks.com \
--cc=nuno.sa@analog.com \
--cc=paul@crapouillou.net \
/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