From: Felipe Ribeiro de Souza <felipers@ime.usp.br>
To: paul@crapouillou.net, jic23@kernel.org, dlechner@baylibre.com,
nuno.sa@analog.com, andy@kernel.org
Cc: Felipe Ribeiro de Souza <felipers@ime.usp.br>,
Lucas Ivars Cadima Ciziks <lucas@ciziks.com>,
linux-mips@vger.kernel.org, linux-iio@vger.kernel.org
Subject: [PATCH] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation
Date: Wed, 15 Apr 2026 22:18:11 -0300 [thread overview]
Message-ID: <20260416011815.9140-1-felipers@ime.usp.br> (raw)
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.
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.
Signed-off-by: Felipe Ribeiro de Souza <felipers@ime.usp.br>
Co-developed-by: Lucas Ivars Cadima Ciziks <lucas@ciziks.com>
Signed-off-by: Lucas Ivars Cadima Ciziks <lucas@ciziks.com>
---
drivers/iio/adc/ingenic-adc.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
index 1e802c877..bb7abdcd8 100644
--- a/drivers/iio/adc/ingenic-adc.c
+++ b/drivers/iio/adc/ingenic-adc.c
@@ -20,6 +20,7 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/cleanup.h>
#define JZ_ADC_REG_ENABLE 0x00
#define JZ_ADC_REG_CFG 0x04
@@ -115,7 +116,7 @@ static void ingenic_adc_set_adcmd(struct iio_dev *iio_dev, unsigned long mask)
{
struct ingenic_adc *adc = iio_priv(iio_dev);
- mutex_lock(&adc->lock);
+ guard(mutex)(&adc->lock);
/* Init ADCMD */
readl(adc->base + JZ_ADC_REG_ADCMD);
@@ -162,8 +163,6 @@ static void ingenic_adc_set_adcmd(struct iio_dev *iio_dev, unsigned long mask)
/* We're done */
writel(0, adc->base + JZ_ADC_REG_ADCMD);
-
- mutex_unlock(&adc->lock);
}
static void ingenic_adc_set_config(struct ingenic_adc *adc,
@@ -172,13 +171,11 @@ static void ingenic_adc_set_config(struct ingenic_adc *adc,
{
uint32_t cfg;
- mutex_lock(&adc->lock);
+ guard(mutex)(&adc->lock);
cfg = readl(adc->base + JZ_ADC_REG_CFG) & ~mask;
cfg |= val;
writel(cfg, adc->base + JZ_ADC_REG_CFG);
-
- mutex_unlock(&adc->lock);
}
static void ingenic_adc_enable_unlocked(struct ingenic_adc *adc,
@@ -201,9 +198,8 @@ static void ingenic_adc_enable(struct ingenic_adc *adc,
int engine,
bool enabled)
{
- mutex_lock(&adc->lock);
+ guard(mutex)(&adc->lock);
ingenic_adc_enable_unlocked(adc, engine, enabled);
- mutex_unlock(&adc->lock);
}
static int ingenic_adc_capture(struct ingenic_adc *adc,
@@ -218,7 +214,7 @@ static int ingenic_adc_capture(struct ingenic_adc *adc,
* probably due to the switch of VREF. We must keep the lock here to
* avoid races with the buffer enable/disable functions.
*/
- mutex_lock(&adc->lock);
+ guard(mutex)(&adc->lock);
cfg = readl(adc->base + JZ_ADC_REG_CFG);
writel(cfg & ~JZ_ADC_REG_CFG_CMD_SEL, adc->base + JZ_ADC_REG_CFG);
@@ -229,7 +225,6 @@ static int ingenic_adc_capture(struct ingenic_adc *adc,
ingenic_adc_enable_unlocked(adc, engine, false);
writel(cfg, adc->base + JZ_ADC_REG_CFG);
- mutex_unlock(&adc->lock);
return ret;
}
@@ -643,7 +638,8 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
}
/* We cannot sample the aux channels in parallel. */
- mutex_lock(&adc->aux_lock);
+ guard(mutex)(&adc->lock);
+
if (adc->soc_data->has_aux_md && engine == 0) {
switch (chan->channel) {
case INGENIC_ADC_AUX0:
@@ -677,7 +673,6 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
ret = IIO_VAL_INT;
out:
- mutex_unlock(&adc->aux_lock);
clk_disable(adc->clk);
return ret;
--
2.43.0
next reply other threads:[~2026-04-16 1:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 1:18 Felipe Ribeiro de Souza [this message]
2026-04-16 10:08 ` [PATCH] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation Paul Cercueil
2026-04-17 5:18 ` Rong Zhang
2026-04-17 8:01 ` Andy Shevchenko
2026-04-19 17:21 ` Jonathan Cameron
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=20260416011815.9140-1-felipers@ime.usp.br \
--to=felipers@ime.usp.br \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--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