Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Educg550 <educg550@usp.br>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
	antoniu.miclaus@analog.com, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org,
	Lucca Ciriac <luccaciriac@usp.br>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
Date: Thu, 7 May 2026 17:24:20 +0100	[thread overview]
Message-ID: <20260507172420.527469b8@jic23-huawei> (raw)
In-Reply-To: <20260506144359.16744-1-educg550@usp.br>

On Wed,  6 May 2026 11:43:59 -0300
Educg550 <educg550@usp.br> wrote:

> From: Eduardo Guedes <educg550@usp.br>

Read submitting patches, particularly about how to send a v2.
Should be [PATCH V2]
> 
> Replace manual mutex_lock()/mutex_unlock() calls with guard(mutex) and
> scoped_guard(mutex) from cleanup.h.
> 
> Using guard(mutex) and scoped_guard(mutex) from cleanup.h allows the
Andy pointed out in another review earlier that it would be clearer to
refer to guard(mutex)()

For scoped_guard() if it were used I'd use scoped_guard(mutex, ...)
to refer to it.

> compiler to enforce lock release on every exit path, eliminating the
> error-prone manual lock/unlock pattern and the goto-based exit labels
> that existed in adf4377_get_freq() and adf4377_set_freq(). This reduces
> the chance of lock imbalance bugs.
> 
> Signed-off-by: Eduardo Guedes <educg550@usp.br>
> Co-developed-by: Lucca Ciriac <luccaciriac@usp.br>
> Signed-off-by: Lucca Ciriac <luccaciriac@usp.br>
> ---

There should be a change log here.  Otherwise just one trivial
request inline for v3.

>  drivers/iio/frequency/adf4377.c | 80 +++++++++++++++------------------
>  1 file changed, 35 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/iio/frequency/adf4377.c b/drivers/iio/frequency/adf4377.c
> index ff6077e29..f91b9c6e2 100644
> --- a/drivers/iio/frequency/adf4377.c
> +++ b/drivers/iio/frequency/adf4377.c

>  static void adf4377_gpio_init(struct adf4377_state *st)
> @@ -919,13 +912,10 @@ static int adf4377_properties_parse(struct adf4377_state *st)
>  static int adf4377_freq_change(struct notifier_block *nb, unsigned long action, void *data)
>  {
>  	struct adf4377_state *st = container_of(nb, struct adf4377_state, nb);
> -	int ret;
>  
>  	if (action == POST_RATE_CHANGE) {
> -		mutex_lock(&st->lock);
> -		ret = notifier_from_errno(adf4377_init(st));
> -		mutex_unlock(&st->lock);
> -		return ret;
> +		guard(mutex)(&st->lock);

Slight preference for a blank line here as the we don't have the same need
for closely associating lock and action as we did with the original code.

> +		return notifier_from_errno(adf4377_init(st));
>  	}
>  
>  	return NOTIFY_OK;


  parent reply	other threads:[~2026-05-07 16:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 14:43 [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard Educg550
2026-05-06 14:57 ` Joshua Crofts
2026-05-07 16:24 ` Jonathan Cameron [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-04-29 20:23 Educg550
2026-04-30  6:03 ` Andy Shevchenko
2026-05-05 16:25   ` Jonathan Cameron
2026-05-05 16:25 ` 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=20260507172420.527469b8@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=dlechner@baylibre.com \
    --cc=educg550@usp.br \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=luccaciriac@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