Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Felipe Ribeiro de Souza <felipers@ime.usp.br>
Cc: andy@kernel.org, dlechner@baylibre.com, jic23@kernel.org,
	nuno.sa@analog.com, paul@crapouillou.net,
	Lucas Ivars Cadima Ciziks <lucas@ciziks.com>,
	linux-iio@vger.kernel.org, linux-mips@vger.kernel.org
Subject: Re: [PATCH v5 3/3] iio: adc: ingenic-adc: use guard()() and scoped_guard() to handle synchronisation
Date: Wed, 6 May 2026 12:19:30 +0300	[thread overview]
Message-ID: <afsHoq_lm9bhZ92r@ashevche-desk.local> (raw)
In-Reply-To: <20260506022454.128169-4-felipers@ime.usp.br>

On Tue, May 05, 2026 at 11:24:30PM -0300, Felipe Ribeiro de Souza wrote:
> Replace mutex_lock() and mutex_unlock() calls with guard()() in
> functions ingenic_adc_set_adcmd(), ingenic_adc_set_config(),
> ingenic_adc_enable(), ingenic_adc_capture(), and with scoped_guard()
> in function 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.

...

>  static void ingenic_adc_set_config(struct ingenic_adc *adc,
>  {
>  	uint32_t cfg;

Side note: We use uXX types in the kernel (you can do a separate change
if you want to).

>  
> -	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);

Side note (in case you want another patch): this is not so robust against
arbitrary values. The traditional pattern of custom FIELD_MODIFY() is this

	cfg = readl(adc->base + JZ_ADC_REG_CFG);
	cfg = (cfg & ~mask) | (val & mask);
	writel(cfg, adc->base + JZ_ADC_REG_CFG);

> -	mutex_unlock(&adc->lock);
>  }

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-05-06  9:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  2:24 [PATCH v5 0/3] iio: adc: ingenic-adc: use guard()() to handle synchronisation and refactor lock-held helpers Felipe Ribeiro de Souza
2026-05-06  2:24 ` [PATCH v5 1/3] iio: adc: ingenic-adc: rename ingenic_adc_enable_unlocked() function Felipe Ribeiro de Souza
2026-05-06  2:24 ` [PATCH v5 2/3] iio: adc: ingenic-adc: refactor ingenic_adc_read_chan_info_raw() Felipe Ribeiro de Souza
2026-05-06  2:24 ` [PATCH v5 3/3] iio: adc: ingenic-adc: use guard()() and scoped_guard() to handle synchronisation Felipe Ribeiro de Souza
2026-05-06  9:19   ` Andy Shevchenko [this message]
2026-05-06  9:20 ` [PATCH v5 0/3] iio: adc: ingenic-adc: use guard()() to handle synchronisation and refactor lock-held helpers Andy Shevchenko
2026-05-06 18:12   ` 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=afsHoq_lm9bhZ92r@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=felipers@ime.usp.br \
    --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