* [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
@ 2026-04-29 20:23 Educg550
2026-04-30 6:03 ` Andy Shevchenko
2026-05-05 16:25 ` Jonathan Cameron
0 siblings, 2 replies; 7+ messages in thread
From: Educg550 @ 2026-04-29 20:23 UTC (permalink / raw)
To: lars, Michael.Hennerich, antoniu.miclaus, jic23, dlechner,
nuno.sa, andy
Cc: educg550, Lucca Ciriac, linux-iio
From: Eduardo Guedes <educg550@usp.br>
Replace manual mutex_lock()/mutex_unlock() calls with guard(mutex) and
scoped_guard(mutex) from cleanup.h.
Signed-off-by: Eduardo Guedes <educg550@usp.br>
Co-developed-by: Lucca Ciriac <luccaciriac@usp.br>
Signed-off-by: Lucca Ciriac <luccaciriac@usp.br>
---
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..461eada66 100644
--- a/drivers/iio/frequency/adf4377.c
+++ b/drivers/iio/frequency/adf4377.c
@@ -7,6 +7,7 @@
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
@@ -518,14 +519,15 @@ static int adf4377_get_freq(struct adf4377_state *st, u64 *freq)
u64 clkin_freq;
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
+
ret = regmap_read(st->regmap, 0x12, &ref_div_factor);
if (ret)
- goto exit;
+ return ret;
ret = regmap_bulk_read(st->regmap, 0x10, st->buf, sizeof(st->buf));
if (ret)
- goto exit;
+ return ret;
clkin_freq = clk_get_rate(st->clkin);
ref_div_factor = FIELD_GET(ADF4377_0012_R_DIV_MSK, ref_div_factor);
@@ -533,10 +535,8 @@ static int adf4377_get_freq(struct adf4377_state *st, u64 *freq)
get_unaligned_le16(&st->buf));
*freq = div_u64(clkin_freq, ref_div_factor) * n_int;
-exit:
- mutex_unlock(&st->lock);
- return ret;
+ return 0;
}
static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
@@ -545,26 +545,24 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
u64 f_vco;
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
- if (freq > ADF4377_MAX_CLKPN_FREQ || freq < ADF4377_MIN_CLKPN_FREQ) {
- ret = -EINVAL;
- goto exit;
- }
+ if (freq > ADF4377_MAX_CLKPN_FREQ || freq < ADF4377_MIN_CLKPN_FREQ)
+ return -EINVAL;
ret = regmap_update_bits(st->regmap, 0x1C, ADF4377_001C_EN_DNCLK_MSK |
ADF4377_001C_EN_DRCLK_MSK,
FIELD_PREP(ADF4377_001C_EN_DNCLK_MSK, 1) |
FIELD_PREP(ADF4377_001C_EN_DRCLK_MSK, 1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x11, ADF4377_0011_EN_AUTOCAL_MSK |
ADF4377_0011_DCLK_DIV2_MSK,
FIELD_PREP(ADF4377_0011_EN_AUTOCAL_MSK, 1) |
FIELD_PREP(ADF4377_0011_DCLK_DIV2_MSK, st->dclk_div2));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2E, ADF4377_002E_EN_ADC_CNV_MSK |
ADF4377_002E_EN_ADC_MSK |
@@ -574,56 +572,56 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_002E_ADC_A_CONV_MSK,
ADF4377_002E_ADC_A_CONV_VCO_CALIB));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x20, ADF4377_0020_EN_ADC_CLK_MSK,
FIELD_PREP(ADF4377_0020_EN_ADC_CLK_MSK, 1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2F, ADF4377_002F_DCLK_DIV1_MSK,
FIELD_PREP(ADF4377_002F_DCLK_DIV1_MSK, st->dclk_div1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x24, ADF4377_0024_DCLK_MODE_MSK,
FIELD_PREP(ADF4377_0024_DCLK_MODE_MSK, st->dclk_mode));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x27,
FIELD_PREP(ADF4377_0027_SYNTH_LOCK_TO_LSB_MSK,
st->synth_lock_timeout));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x28, ADF4377_0028_SYNTH_LOCK_TO_MSB_MSK,
FIELD_PREP(ADF4377_0028_SYNTH_LOCK_TO_MSB_MSK,
st->synth_lock_timeout >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x29,
FIELD_PREP(ADF4377_0029_VCO_ALC_TO_LSB_MSK,
st->vco_alc_timeout));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2A, ADF4377_002A_VCO_ALC_TO_MSB_MSK,
FIELD_PREP(ADF4377_002A_VCO_ALC_TO_MSB_MSK,
st->vco_alc_timeout >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x26,
FIELD_PREP(ADF4377_0026_VCO_BAND_DIV_MSK, st->vco_band_div));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x2D,
FIELD_PREP(ADF4377_002D_ADC_CLK_DIV_MSK, st->adc_clk_div));
if (ret)
- goto exit;
+ return ret;
st->clkout_div_sel = 0;
@@ -641,24 +639,24 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_0011_EN_RDBLR_MSK, 0) |
FIELD_PREP(ADF4377_0011_N_INT_MSB_MSK, st->n_int >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x12, ADF4377_0012_R_DIV_MSK |
ADF4377_0012_CLKOUT_DIV_MSK,
FIELD_PREP(ADF4377_0012_CLKOUT_DIV_MSK, st->clkout_div_sel) |
FIELD_PREP(ADF4377_0012_R_DIV_MSK, st->ref_div_factor));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x10,
FIELD_PREP(ADF4377_0010_N_INT_LSB_MSK, st->n_int));
if (ret)
- goto exit;
+ return ret;
ret = regmap_read_poll_timeout(st->regmap, 0x49, read_val,
!(read_val & (ADF4377_0049_FSM_BUSY_MSK)), 200, 200 * 100);
if (ret)
- goto exit;
+ return ret;
/* Disable EN_DNCLK, EN_DRCLK */
ret = regmap_update_bits(st->regmap, 0x1C, ADF4377_001C_EN_DNCLK_MSK |
@@ -666,26 +664,21 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_001C_EN_DNCLK_MSK, 0) |
FIELD_PREP(ADF4377_001C_EN_DRCLK_MSK, 0));
if (ret)
- goto exit;
+ return ret;
/* Disable EN_ADC_CLK */
ret = regmap_update_bits(st->regmap, 0x20, ADF4377_0020_EN_ADC_CLK_MSK,
FIELD_PREP(ADF4377_0020_EN_ADC_CLK_MSK, 0));
if (ret)
- goto exit;
+ return ret;
/* Set output Amplitude */
- ret = regmap_update_bits(st->regmap, 0x19, ADF4377_0019_CLKOUT2_OP_MSK |
- ADF4377_0019_CLKOUT1_OP_MSK,
- FIELD_PREP(ADF4377_0019_CLKOUT1_OP_MSK,
- ADF4377_0019_CLKOUT_420MV) |
- FIELD_PREP(ADF4377_0019_CLKOUT2_OP_MSK,
- ADF4377_0019_CLKOUT_420MV));
-
-exit:
- mutex_unlock(&st->lock);
-
- return ret;
+ return regmap_update_bits(st->regmap, 0x19, ADF4377_0019_CLKOUT2_OP_MSK |
+ ADF4377_0019_CLKOUT1_OP_MSK,
+ FIELD_PREP(ADF4377_0019_CLKOUT1_OP_MSK,
+ ADF4377_0019_CLKOUT_420MV) |
+ FIELD_PREP(ADF4377_0019_CLKOUT2_OP_MSK,
+ ADF4377_0019_CLKOUT_420MV));
}
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;
+ scoped_guard(mutex, &st->lock)
+ return notifier_from_errno(adf4377_init(st));
}
return NOTIFY_OK;
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
2026-04-29 20:23 [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard Educg550
@ 2026-04-30 6:03 ` Andy Shevchenko
2026-05-05 16:25 ` Jonathan Cameron
2026-05-05 16:25 ` Jonathan Cameron
1 sibling, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2026-04-30 6:03 UTC (permalink / raw)
To: Educg550
Cc: lars, Michael.Hennerich, antoniu.miclaus, jic23, dlechner,
nuno.sa, andy, Lucca Ciriac, linux-iio
On Wed, Apr 29, 2026 at 05:23:04PM -0300, Educg550 wrote:
> Replace manual mutex_lock()/mutex_unlock() calls with guard(mutex) and
> scoped_guard(mutex) from cleanup.h.
...
> 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;
> + scoped_guard(mutex, &st->lock)
> + return notifier_from_errno(adf4377_init(st));
The scoped_guard() makes more sense when we have some code in between before
returning, here the guard()() fits much better.
Alternatively:
scoped_guard(mutex, &st->lock)
ret = adf4377_init(st);
return notifier_from_errno(ret);
> }
>
> return NOTIFY_OK;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
2026-04-30 6:03 ` Andy Shevchenko
@ 2026-05-05 16:25 ` Jonathan Cameron
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-05-05 16:25 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Educg550, lars, Michael.Hennerich, antoniu.miclaus, dlechner,
nuno.sa, andy, Lucca Ciriac, linux-iio
On Thu, 30 Apr 2026 09:03:21 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Apr 29, 2026 at 05:23:04PM -0300, Educg550 wrote:
>
> > Replace manual mutex_lock()/mutex_unlock() calls with guard(mutex) and
> > scoped_guard(mutex) from cleanup.h.
>
> ...
>
> > 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;
> > + scoped_guard(mutex, &st->lock)
> > + return notifier_from_errno(adf4377_init(st));
>
> The scoped_guard() makes more sense when we have some code in between before
> returning, here the guard()() fits much better.
FWIW I prefer this option.
>
> Alternatively:
>
> scoped_guard(mutex, &st->lock)
> ret = adf4377_init(st);
> return notifier_from_errno(ret);
>
> > }
> >
> > return NOTIFY_OK;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
2026-04-29 20:23 [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard Educg550
2026-04-30 6:03 ` Andy Shevchenko
@ 2026-05-05 16:25 ` Jonathan Cameron
1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-05-05 16:25 UTC (permalink / raw)
To: Educg550
Cc: lars, Michael.Hennerich, antoniu.miclaus, dlechner, nuno.sa, andy,
Lucca Ciriac, linux-iio
On Wed, 29 Apr 2026 17:23:04 -0300
Educg550 <educg550@usp.br> wrote:
> From: Eduardo Guedes <educg550@usp.br>
>
> Replace manual mutex_lock()/mutex_unlock() calls with guard(mutex) and
> scoped_guard(mutex) from cleanup.h.
Why? The patch description must provide an explanation on why the
change justifies the burden of churn to the driver + reviewer time.
>
> Signed-off-by: Eduardo Guedes <educg550@usp.br>
> Co-developed-by: Lucca Ciriac <luccaciriac@usp.br>
> Signed-off-by: Lucca Ciriac <luccaciriac@usp.br>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
@ 2026-05-06 14:43 Educg550
2026-05-06 14:57 ` Joshua Crofts
2026-05-07 16:24 ` Jonathan Cameron
0 siblings, 2 replies; 7+ messages in thread
From: Educg550 @ 2026-05-06 14:43 UTC (permalink / raw)
To: lars, Michael.Hennerich, antoniu.miclaus, jic23, dlechner,
nuno.sa, andy
Cc: educg550, Lucca Ciriac, linux-iio
From: Eduardo Guedes <educg550@usp.br>
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
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>
---
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
@@ -7,6 +7,7 @@
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
@@ -518,14 +519,15 @@ static int adf4377_get_freq(struct adf4377_state *st, u64 *freq)
u64 clkin_freq;
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
+
ret = regmap_read(st->regmap, 0x12, &ref_div_factor);
if (ret)
- goto exit;
+ return ret;
ret = regmap_bulk_read(st->regmap, 0x10, st->buf, sizeof(st->buf));
if (ret)
- goto exit;
+ return ret;
clkin_freq = clk_get_rate(st->clkin);
ref_div_factor = FIELD_GET(ADF4377_0012_R_DIV_MSK, ref_div_factor);
@@ -533,10 +535,8 @@ static int adf4377_get_freq(struct adf4377_state *st, u64 *freq)
get_unaligned_le16(&st->buf));
*freq = div_u64(clkin_freq, ref_div_factor) * n_int;
-exit:
- mutex_unlock(&st->lock);
- return ret;
+ return 0;
}
static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
@@ -545,26 +545,24 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
u64 f_vco;
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
- if (freq > ADF4377_MAX_CLKPN_FREQ || freq < ADF4377_MIN_CLKPN_FREQ) {
- ret = -EINVAL;
- goto exit;
- }
+ if (freq > ADF4377_MAX_CLKPN_FREQ || freq < ADF4377_MIN_CLKPN_FREQ)
+ return -EINVAL;
ret = regmap_update_bits(st->regmap, 0x1C, ADF4377_001C_EN_DNCLK_MSK |
ADF4377_001C_EN_DRCLK_MSK,
FIELD_PREP(ADF4377_001C_EN_DNCLK_MSK, 1) |
FIELD_PREP(ADF4377_001C_EN_DRCLK_MSK, 1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x11, ADF4377_0011_EN_AUTOCAL_MSK |
ADF4377_0011_DCLK_DIV2_MSK,
FIELD_PREP(ADF4377_0011_EN_AUTOCAL_MSK, 1) |
FIELD_PREP(ADF4377_0011_DCLK_DIV2_MSK, st->dclk_div2));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2E, ADF4377_002E_EN_ADC_CNV_MSK |
ADF4377_002E_EN_ADC_MSK |
@@ -574,56 +572,56 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_002E_ADC_A_CONV_MSK,
ADF4377_002E_ADC_A_CONV_VCO_CALIB));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x20, ADF4377_0020_EN_ADC_CLK_MSK,
FIELD_PREP(ADF4377_0020_EN_ADC_CLK_MSK, 1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2F, ADF4377_002F_DCLK_DIV1_MSK,
FIELD_PREP(ADF4377_002F_DCLK_DIV1_MSK, st->dclk_div1));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x24, ADF4377_0024_DCLK_MODE_MSK,
FIELD_PREP(ADF4377_0024_DCLK_MODE_MSK, st->dclk_mode));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x27,
FIELD_PREP(ADF4377_0027_SYNTH_LOCK_TO_LSB_MSK,
st->synth_lock_timeout));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x28, ADF4377_0028_SYNTH_LOCK_TO_MSB_MSK,
FIELD_PREP(ADF4377_0028_SYNTH_LOCK_TO_MSB_MSK,
st->synth_lock_timeout >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x29,
FIELD_PREP(ADF4377_0029_VCO_ALC_TO_LSB_MSK,
st->vco_alc_timeout));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x2A, ADF4377_002A_VCO_ALC_TO_MSB_MSK,
FIELD_PREP(ADF4377_002A_VCO_ALC_TO_MSB_MSK,
st->vco_alc_timeout >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x26,
FIELD_PREP(ADF4377_0026_VCO_BAND_DIV_MSK, st->vco_band_div));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x2D,
FIELD_PREP(ADF4377_002D_ADC_CLK_DIV_MSK, st->adc_clk_div));
if (ret)
- goto exit;
+ return ret;
st->clkout_div_sel = 0;
@@ -641,24 +639,24 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_0011_EN_RDBLR_MSK, 0) |
FIELD_PREP(ADF4377_0011_N_INT_MSB_MSK, st->n_int >> 8));
if (ret)
- goto exit;
+ return ret;
ret = regmap_update_bits(st->regmap, 0x12, ADF4377_0012_R_DIV_MSK |
ADF4377_0012_CLKOUT_DIV_MSK,
FIELD_PREP(ADF4377_0012_CLKOUT_DIV_MSK, st->clkout_div_sel) |
FIELD_PREP(ADF4377_0012_R_DIV_MSK, st->ref_div_factor));
if (ret)
- goto exit;
+ return ret;
ret = regmap_write(st->regmap, 0x10,
FIELD_PREP(ADF4377_0010_N_INT_LSB_MSK, st->n_int));
if (ret)
- goto exit;
+ return ret;
ret = regmap_read_poll_timeout(st->regmap, 0x49, read_val,
!(read_val & (ADF4377_0049_FSM_BUSY_MSK)), 200, 200 * 100);
if (ret)
- goto exit;
+ return ret;
/* Disable EN_DNCLK, EN_DRCLK */
ret = regmap_update_bits(st->regmap, 0x1C, ADF4377_001C_EN_DNCLK_MSK |
@@ -666,26 +664,21 @@ static int adf4377_set_freq(struct adf4377_state *st, u64 freq)
FIELD_PREP(ADF4377_001C_EN_DNCLK_MSK, 0) |
FIELD_PREP(ADF4377_001C_EN_DRCLK_MSK, 0));
if (ret)
- goto exit;
+ return ret;
/* Disable EN_ADC_CLK */
ret = regmap_update_bits(st->regmap, 0x20, ADF4377_0020_EN_ADC_CLK_MSK,
FIELD_PREP(ADF4377_0020_EN_ADC_CLK_MSK, 0));
if (ret)
- goto exit;
+ return ret;
/* Set output Amplitude */
- ret = regmap_update_bits(st->regmap, 0x19, ADF4377_0019_CLKOUT2_OP_MSK |
- ADF4377_0019_CLKOUT1_OP_MSK,
- FIELD_PREP(ADF4377_0019_CLKOUT1_OP_MSK,
- ADF4377_0019_CLKOUT_420MV) |
- FIELD_PREP(ADF4377_0019_CLKOUT2_OP_MSK,
- ADF4377_0019_CLKOUT_420MV));
-
-exit:
- mutex_unlock(&st->lock);
-
- return ret;
+ return regmap_update_bits(st->regmap, 0x19, ADF4377_0019_CLKOUT2_OP_MSK |
+ ADF4377_0019_CLKOUT1_OP_MSK,
+ FIELD_PREP(ADF4377_0019_CLKOUT1_OP_MSK,
+ ADF4377_0019_CLKOUT_420MV) |
+ FIELD_PREP(ADF4377_0019_CLKOUT2_OP_MSK,
+ ADF4377_0019_CLKOUT_420MV));
}
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);
+ return notifier_from_errno(adf4377_init(st));
}
return NOTIFY_OK;
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
2026-05-06 14:43 Educg550
@ 2026-05-06 14:57 ` Joshua Crofts
2026-05-07 16:24 ` Jonathan Cameron
1 sibling, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-05-06 14:57 UTC (permalink / raw)
To: Educg550
Cc: lars, Michael.Hennerich, antoniu.miclaus, jic23, dlechner,
nuno.sa, andy, Lucca Ciriac, linux-iio
On Wed, 6 May 2026 at 16:46, Educg550 <educg550@usp.br> wrote:
>
> From: Eduardo Guedes <educg550@usp.br>
>
> 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
> 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>
Codewise LGTM, but you mention scoped_guard()() in the commit message,
yet I don't see any uses of it in the patch (perhaps Jonathan can tweak that).
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard
2026-05-06 14:43 Educg550
2026-05-06 14:57 ` Joshua Crofts
@ 2026-05-07 16:24 ` Jonathan Cameron
1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-05-07 16:24 UTC (permalink / raw)
To: Educg550
Cc: lars, Michael.Hennerich, antoniu.miclaus, dlechner, nuno.sa, andy,
Lucca Ciriac, linux-iio
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-05-07 16:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29 20:23 [PATCH] iio: frequency: adf4377: replace mutex_lock/unlock with guard and scoped_guard Educg550
2026-04-30 6:03 ` Andy Shevchenko
2026-05-05 16:25 ` Jonathan Cameron
2026-05-05 16:25 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2026-05-06 14:43 Educg550
2026-05-06 14:57 ` Joshua Crofts
2026-05-07 16:24 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox