* [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
@ 2026-03-19 18:46 Matheus Giarola
2026-03-20 19:53 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Matheus Giarola @ 2026-03-19 18:46 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, matheusgiarola,
arthurpilone, davidbtadokoro
Use guard(mutex) instead of mutex_lock()/mutex_unlock(),
ensuring the mutex is released automatically when leaving
the function scope. The change improves error handling and
avoids issues such as missing unlocks. It also simplifies the
code by removing 'err_unlock' label and several mutex_unlock()
calls.
Signed-off-by: Matheus Giarola <matheusgiarola@usp.br>
---
drivers/iio/adc/ad7280a.c | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c
index ba12a3796e2b..3a4f0dd37d78 100644
--- a/drivers/iio/adc/ad7280a.c
+++ b/drivers/iio/adc/ad7280a.c
@@ -496,7 +496,7 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
devaddr = chan->address >> 8;
ch = chan->address & 0xFF;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
if (readin)
st->cb_mask[devaddr] |= BIT(ch);
else
@@ -505,7 +505,6 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE_REG, 0,
FIELD_PREP(AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK,
st->cb_mask[devaddr]));
- mutex_unlock(&st->lock);
return ret ? ret : len;
}
@@ -519,10 +518,9 @@ static ssize_t ad7280_show_balance_timer(struct iio_dev *indio_dev,
unsigned int msecs;
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
ret = ad7280_read_reg(st, chan->address >> 8,
(chan->address & 0xFF) + AD7280A_CB1_TIMER_REG);
- mutex_unlock(&st->lock);
if (ret < 0)
return ret;
@@ -551,11 +549,10 @@ static ssize_t ad7280_store_balance_timer(struct iio_dev *indio_dev,
if (val > 31)
return -EINVAL;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
ret = ad7280_write(st, chan->address >> 8,
(chan->address & 0xFF) + AD7280A_CB1_TIMER_REG, 0,
FIELD_PREP(AD7280A_CB_TIMER_VAL_MSK, val));
- mutex_unlock(&st->lock);
return ret ? ret : len;
}
@@ -737,7 +734,7 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
if (val2 != 0)
return -EINVAL;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
switch (chan->type) {
case IIO_VOLTAGE:
value = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */
@@ -760,8 +757,7 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
st->cell_threshlow = value;
break;
default:
- ret = -EINVAL;
- goto err_unlock;
+ return -EINVAL;
}
break;
case IIO_TEMP:
@@ -785,18 +781,12 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
st->aux_threshlow = value;
break;
default:
- ret = -EINVAL;
- goto err_unlock;
+ return -EINVAL;
}
break;
default:
- ret = -EINVAL;
- goto err_unlock;
+ return -EINVAL;
}
-
-err_unlock:
- mutex_unlock(&st->lock);
-
return ret;
}
@@ -885,13 +875,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
switch (m) {
case IIO_CHAN_INFO_RAW:
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
if (chan->address == AD7280A_ALL_CELLS)
ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
else
ret = ad7280_read_channel(st, chan->address >> 8,
chan->address & 0xFF);
- mutex_unlock(&st->lock);
if (ret < 0)
return ret;
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
2026-03-19 18:46 [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex) Matheus Giarola
@ 2026-03-20 19:53 ` kernel test robot
2026-03-20 20:16 ` kernel test robot
2026-03-21 15:55 ` Jonathan Cameron
2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-03-20 19:53 UTC (permalink / raw)
To: Matheus Giarola, lars, Michael.Hennerich, jic23
Cc: oe-kbuild-all, dlechner, nuno.sa, andy, linux-iio, linux-kernel,
matheusgiarola, arthurpilone, davidbtadokoro
Hi Matheus,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v7.0-rc4 next-20260320]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matheus-Giarola/iio-adc-ad7280a-replace-mutex_lock-with-guard-mutex/20260320-142509
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20260319184615.10970-1-matheusgiarola%40usp.br
patch subject: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
config: parisc-randconfig-002-20260321 (https://download.01.org/0day-ci/archive/20260321/202603210357.KTWqlL36-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 9.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260321/202603210357.KTWqlL36-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603210357.KTWqlL36-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/iio/adc/ad7280a.c:10:
drivers/iio/adc/ad7280a.c: In function 'ad7280_read_raw':
>> include/linux/cleanup.h:299:2: error: a label can only be part of a statement and a declaration is not a statement
299 | class_##_name##_t var __cleanup(class_##_name##_destructor) = \
| ^~~~~~
include/linux/cleanup.h:419:2: note: in expansion of macro 'CLASS'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^~~~~
drivers/iio/adc/ad7280a.c:878:3: note: in expansion of macro 'guard'
878 | guard(mutex)(&st->lock);
| ^~~~~
--
In file included from ad7280a.c:10:
ad7280a.c: In function 'ad7280_read_raw':
>> include/linux/cleanup.h:299:2: error: a label can only be part of a statement and a declaration is not a statement
299 | class_##_name##_t var __cleanup(class_##_name##_destructor) = \
| ^~~~~~
include/linux/cleanup.h:419:2: note: in expansion of macro 'CLASS'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^~~~~
ad7280a.c:878:3: note: in expansion of macro 'guard'
878 | guard(mutex)(&st->lock);
| ^~~~~
vim +299 include/linux/cleanup.h
54da6a0924311c Peter Zijlstra 2023-05-26 297
54da6a0924311c Peter Zijlstra 2023-05-26 298 #define CLASS(_name, var) \
54da6a0924311c Peter Zijlstra 2023-05-26 @299 class_##_name##_t var __cleanup(class_##_name##_destructor) = \
54da6a0924311c Peter Zijlstra 2023-05-26 300 class_##_name##_constructor
54da6a0924311c Peter Zijlstra 2023-05-26 301
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
2026-03-19 18:46 [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex) Matheus Giarola
2026-03-20 19:53 ` kernel test robot
@ 2026-03-20 20:16 ` kernel test robot
2026-03-21 15:55 ` Jonathan Cameron
2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-03-20 20:16 UTC (permalink / raw)
To: Matheus Giarola, lars, Michael.Hennerich, jic23
Cc: llvm, oe-kbuild-all, dlechner, nuno.sa, andy, linux-iio,
linux-kernel, matheusgiarola, arthurpilone, davidbtadokoro
Hi Matheus,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v7.0-rc4 next-20260320]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matheus-Giarola/iio-adc-ad7280a-replace-mutex_lock-with-guard-mutex/20260320-142509
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20260319184615.10970-1-matheusgiarola%40usp.br
patch subject: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
config: arm-randconfig-004-20260321 (https://download.01.org/0day-ci/archive/20260321/202603210411.t4KwH3aX-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 4abb927bacf37f18f6359a41639a6d1b3bffffb5)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260321/202603210411.t4KwH3aX-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603210411.t4KwH3aX-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/iio/adc/ad7280a.c:899:2: error: cannot jump from switch statement to this case label
899 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
| ^
drivers/iio/adc/ad7280a.c:878:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
878 | guard(mutex)(&st->lock);
| ^
include/linux/cleanup.h:419:2: note: expanded from macro 'guard'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^
include/linux/cleanup.h:300:3: note: expanded from macro 'CLASS'
300 | class_##_name##_constructor
| ^
<scratch space>:15:1: note: expanded from here
15 | class_mutex_constructor
| ^
note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
16 | #define __PASTE(a, b) ___PASTE(a, b)
| ^
include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
15 | #define ___PASTE(a, b) a##b
| ^
<scratch space>:21:1: note: expanded from here
21 | __UNIQUE_ID_unlock_538
| ^
drivers/iio/adc/ad7280a.c:878:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
include/linux/cleanup.h:419:15: note: expanded from macro 'guard'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^
include/linux/compiler.h:168:2: note: expanded from macro '__UNIQUE_ID'
168 | __PASTE(__UNIQUE_ID_, \
| ^
include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
16 | #define __PASTE(a, b) ___PASTE(a, b)
| ^
include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
15 | #define ___PASTE(a, b) a##b
| ^
<scratch space>:9:1: note: expanded from here
9 | __UNIQUE_ID_guard_537
| ^
drivers/iio/adc/ad7280a.c:891:2: error: cannot jump from switch statement to this case label
891 | case IIO_CHAN_INFO_SCALE:
| ^
drivers/iio/adc/ad7280a.c:878:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
878 | guard(mutex)(&st->lock);
| ^
include/linux/cleanup.h:419:2: note: expanded from macro 'guard'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^
include/linux/cleanup.h:300:3: note: expanded from macro 'CLASS'
300 | class_##_name##_constructor
| ^
<scratch space>:15:1: note: expanded from here
15 | class_mutex_constructor
| ^
note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
16 | #define __PASTE(a, b) ___PASTE(a, b)
| ^
include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
15 | #define ___PASTE(a, b) a##b
| ^
<scratch space>:21:1: note: expanded from here
21 | __UNIQUE_ID_unlock_538
| ^
drivers/iio/adc/ad7280a.c:878:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
include/linux/cleanup.h:419:15: note: expanded from macro 'guard'
419 | CLASS(_name, __UNIQUE_ID(guard))
| ^
include/linux/compiler.h:168:2: note: expanded from macro '__UNIQUE_ID'
168 | __PASTE(__UNIQUE_ID_, \
| ^
include/linux/compiler_types.h:16:23: note: expanded from macro '__PASTE'
16 | #define __PASTE(a, b) ___PASTE(a, b)
| ^
include/linux/compiler_types.h:15:24: note: expanded from macro '___PASTE'
15 | #define ___PASTE(a, b) a##b
| ^
<scratch space>:9:1: note: expanded from here
9 | __UNIQUE_ID_guard_537
| ^
2 errors generated.
vim +899 drivers/iio/adc/ad7280a.c
c5fe2f537b91e17 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2022-02-06 866
84f79ecb0c1f393 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2011-10-06 867 static int ad7280_read_raw(struct iio_dev *indio_dev,
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 868 struct iio_chan_spec const *chan,
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 869 int *val,
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 870 int *val2,
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 871 long m)
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 872 {
84f79ecb0c1f393 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2011-10-06 873 struct ad7280_state *st = iio_priv(indio_dev);
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 874 int ret;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 875
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 876 switch (m) {
b11f98ff8c35d62 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2012-04-15 877 case IIO_CHAN_INFO_RAW:
801020aafb667e4 drivers/iio/adc/ad7280a.c Matheus Giarola 2026-03-19 878 guard(mutex)(&st->lock);
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 879 if (chan->address == AD7280A_ALL_CELLS)
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 880 ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 881 else
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 882 ret = ad7280_read_channel(st, chan->address >> 8,
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 883 chan->address & 0xFF);
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 884
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 885 if (ret < 0)
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 886 return ret;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 887
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 888 *val = ret;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 889
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 890 return IIO_VAL_INT;
c8a9f8056f40f62 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2011-10-26 891 case IIO_CHAN_INFO_SCALE:
4c59aabd9a93d8f drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2022-02-06 892 if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6_REG)
d6570b33a1c0620 drivers/staging/iio/adc/ad7280a.c Lars-Peter Clausen 2013-09-28 893 *val = 4000;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 894 else
d6570b33a1c0620 drivers/staging/iio/adc/ad7280a.c Lars-Peter Clausen 2013-09-28 895 *val = 5000;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 896
d6570b33a1c0620 drivers/staging/iio/adc/ad7280a.c Lars-Peter Clausen 2013-09-28 897 *val2 = AD7280A_BITS;
d6570b33a1c0620 drivers/staging/iio/adc/ad7280a.c Lars-Peter Clausen 2013-09-28 898 return IIO_VAL_FRACTIONAL_LOG2;
c5fe2f537b91e17 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2022-02-06 @899 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
c5fe2f537b91e17 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2022-02-06 900 *val = ad7280a_n_avg[st->oversampling_ratio];
c5fe2f537b91e17 drivers/staging/iio/adc/ad7280a.c Jonathan Cameron 2022-02-06 901 return IIO_VAL_INT;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 902 }
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 903 return -EINVAL;
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 904 }
2051f25d2a26573 drivers/staging/iio/adc/ad7280a.c Michael Hennerich 2011-07-20 905
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
2026-03-19 18:46 [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex) Matheus Giarola
2026-03-20 19:53 ` kernel test robot
2026-03-20 20:16 ` kernel test robot
@ 2026-03-21 15:55 ` Jonathan Cameron
2026-03-25 19:21 ` Matheus Giarola
2 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2026-03-21 15:55 UTC (permalink / raw)
To: Matheus Giarola
Cc: lars, Michael.Hennerich, dlechner, nuno.sa, andy, linux-iio,
linux-kernel, matheusgiarola, arthurpilone, davidbtadokoro
On Thu, 19 Mar 2026 15:46:15 -0300
Matheus Giarola <matheustpgiarola@gmail.com> wrote:
> Use guard(mutex) instead of mutex_lock()/mutex_unlock(),
> ensuring the mutex is released automatically when leaving
> the function scope. The change improves error handling and
> avoids issues such as missing unlocks. It also simplifies the
> code by removing 'err_unlock' label and several mutex_unlock()
> calls.
>
> Signed-off-by: Matheus Giarola <matheusgiarola@usp.br>
Hi Matheus.
> @@ -885,13 +875,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
>
> switch (m) {
> case IIO_CHAN_INFO_RAW:
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
Scope missing...
Thanks,
Jonathan
> if (chan->address == AD7280A_ALL_CELLS)
> ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
> else
> ret = ad7280_read_channel(st, chan->address >> 8,
> chan->address & 0xFF);
> - mutex_unlock(&st->lock);
>
> if (ret < 0)
> return ret;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
2026-03-21 15:55 ` Jonathan Cameron
@ 2026-03-25 19:21 ` Matheus Giarola
2026-03-25 20:32 ` Jonathan Cameron
0 siblings, 1 reply; 6+ messages in thread
From: Matheus Giarola @ 2026-03-25 19:21 UTC (permalink / raw)
To: Jonathan Cameron
Cc: lars, Michael.Hennerich, dlechner, nuno.sa, andy, linux-iio,
linux-kernel, matheusgiarola, arthurpilone, davidbtadokoro
On Sat, Mar 21, 2026 at 12:55 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Thu, 19 Mar 2026 15:46:15 -0300
> Matheus Giarola <matheustpgiarola@gmail.com> wrote:
>
> > Use guard(mutex) instead of mutex_lock()/mutex_unlock(),
> > ensuring the mutex is released automatically when leaving
> > the function scope. The change improves error handling and
> > avoids issues such as missing unlocks. It also simplifies the
> > code by removing 'err_unlock' label and several mutex_unlock()
> > calls.
> >
> > Signed-off-by: Matheus Giarola <matheusgiarola@usp.br>
> Hi Matheus.
>
>
> > @@ -885,13 +875,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
> >
> > switch (m) {
> > case IIO_CHAN_INFO_RAW:
> > - mutex_lock(&st->lock);
> > + guard(mutex)(&st->lock);
>
> Scope missing...
>
> Thanks,
>
> Jonathan
Hi Jonathan,
Thank you for the review and pointing out the missing scope, I'll fix
it by using
scoped_guard() to ensure the lock is released at the right time.
I'm a bit busy with university work this week, so at most by next week I'll send
a v2 of this patch.
Best regards,
Matheus
>
> > if (chan->address == AD7280A_ALL_CELLS)
> > ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
> > else
> > ret = ad7280_read_channel(st, chan->address >> 8,
> > chan->address & 0xFF);
> > - mutex_unlock(&st->lock);
> >
> > if (ret < 0)
> > return ret;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex)
2026-03-25 19:21 ` Matheus Giarola
@ 2026-03-25 20:32 ` Jonathan Cameron
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2026-03-25 20:32 UTC (permalink / raw)
To: Matheus Giarola
Cc: lars, Michael.Hennerich, dlechner, nuno.sa, andy, linux-iio,
linux-kernel, matheusgiarola, arthurpilone, davidbtadokoro
On Wed, 25 Mar 2026 16:21:04 -0300
Matheus Giarola <matheustpgiarola@gmail.com> wrote:
> On Sat, Mar 21, 2026 at 12:55 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Thu, 19 Mar 2026 15:46:15 -0300
> > Matheus Giarola <matheustpgiarola@gmail.com> wrote:
> >
> > > Use guard(mutex) instead of mutex_lock()/mutex_unlock(),
> > > ensuring the mutex is released automatically when leaving
> > > the function scope. The change improves error handling and
> > > avoids issues such as missing unlocks. It also simplifies the
> > > code by removing 'err_unlock' label and several mutex_unlock()
> > > calls.
> > >
> > > Signed-off-by: Matheus Giarola <matheusgiarola@usp.br>
> > Hi Matheus.
> >
> >
> > > @@ -885,13 +875,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
> > >
> > > switch (m) {
> > > case IIO_CHAN_INFO_RAW:
> > > - mutex_lock(&st->lock);
> > > + guard(mutex)(&st->lock);
> >
> > Scope missing...
> >
> > Thanks,
> >
> > Jonathan
>
> Hi Jonathan,
>
> Thank you for the review and pointing out the missing scope, I'll fix
> it by using
> scoped_guard() to ensure the lock is released at the right time.
nope. Whilst that would be correct it's not the nicest solution.
Instead do what you'd do if there was a variable declared in a case
block..
case IIO_CHAN_INFO_RAW: {
guard(...)(..);
...
}
Under the hood guard is declaring a local variable.
>
> I'm a bit busy with university work this week, so at most by next week I'll send
> a v2 of this patch.
>
> Best regards,
>
> Matheus
> >
> > > if (chan->address == AD7280A_ALL_CELLS)
> > > ret = ad7280_read_all_channels(st, st->scan_cnt, NULL);
> > > else
> > > ret = ad7280_read_channel(st, chan->address >> 8,
> > > chan->address & 0xFF);
> > > - mutex_unlock(&st->lock);
> > >
> > > if (ret < 0)
> > > return ret;
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-25 20:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 18:46 [PATCH] iio: adc: ad7280a: replace mutex_lock() with guard(mutex) Matheus Giarola
2026-03-20 19:53 ` kernel test robot
2026-03-20 20:16 ` kernel test robot
2026-03-21 15:55 ` Jonathan Cameron
2026-03-25 19:21 ` Matheus Giarola
2026-03-25 20:32 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox