public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Felipe Ribeiro de Souza <felipers@ime.usp.br>
Cc: paul@crapouillou.net, jic23@kernel.org, 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 v2] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation
Date: Mon, 20 Apr 2026 11:37:56 +0300	[thread overview]
Message-ID: <aeXl5BO91iRUqNWp@ashevche-desk.local> (raw)
In-Reply-To: <20260419152917.8984-1-felipers@ime.usp.br>

On Sun, Apr 19, 2026 at 12:27:34PM -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 with scoped_guard(mutex, &lock) 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.

...

>  	/* We cannot sample the aux channels in parallel. */
> -	mutex_lock(&adc->aux_lock);
> -	if (adc->soc_data->has_aux_md && engine == 0) {
> +	scoped_guard(mutex, &adc->lock) {

This makes a bit noisy refactoring, hard to follow. Perhaps, split out
the helper function first (in a separate change) and then use guard()()
there.

> +		if (adc->soc_data->has_aux_md && engine == 0) {
> +			switch (chan->channel) {
> +			case INGENIC_ADC_AUX0:
> +				cmd = 0;
> +				break;
> +			case INGENIC_ADC_AUX:
> +				cmd = 1;
> +				break;
> +			case INGENIC_ADC_AUX2:
> +				cmd = 2;
> +				break;
> +			}
> +	
> +			ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd);
> +		}
> +	
> +		ret = ingenic_adc_capture(adc, engine);
> +		if (ret)
> +			goto out;
> +	
>  		switch (chan->channel) {
>  		case INGENIC_ADC_AUX0:
> -			cmd = 0;
> -			break;
>  		case INGENIC_ADC_AUX:
> -			cmd = 1;
> -			break;
>  		case INGENIC_ADC_AUX2:
> -			cmd = 2;
> +			*val = readw(adc->base + JZ_ADC_REG_ADSDAT);
> +			break;
> +		case INGENIC_ADC_BATTERY:
> +			*val = readw(adc->base + JZ_ADC_REG_ADBDAT);
>  			break;
>  		}
> -
> -		ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd);
> -	}
> -
> -	ret = ingenic_adc_capture(adc, engine);
> -	if (ret)
> -		goto out;
> -
> -	switch (chan->channel) {
> -	case INGENIC_ADC_AUX0:
> -	case INGENIC_ADC_AUX:
> -	case INGENIC_ADC_AUX2:
> -		*val = readw(adc->base + JZ_ADC_REG_ADSDAT);
> -		break;
> -	case INGENIC_ADC_BATTERY:
> -		*val = readw(adc->base + JZ_ADC_REG_ADBDAT);
> -		break;
> +	
> +		ret = IIO_VAL_INT;
>  	}
> -
> -	ret = IIO_VAL_INT;
>  out:
> -	mutex_unlock(&adc->aux_lock);
>  	clk_disable(adc->clk);
>  
>  	return ret;

Alternatively, propose the respective ACQUIRE*() macros to CCF.

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-04-20  8:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 15:27 [PATCH v2] iio: adc: ingenic-adc: use guard(mutex)(&lock) to handle synchronisation Felipe Ribeiro de Souza
2026-04-20  8:37 ` 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=aeXl5BO91iRUqNWp@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