* [PATCH v2] iio: adc: ti-ads7924: Use guard(mutex) in ADC read helper
@ 2026-04-20 11:34 Giorgi Tchankvetadze
2026-04-21 14:58 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Giorgi Tchankvetadze @ 2026-04-20 11:34 UTC (permalink / raw)
To: antoniu.miclaus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel,
Giorgi Tchankvetadze
Replace mutex_lock()/mutex_unlock() pair with guard(mutex)()
and move the lock into ads7924_get_adc_result(). Keeping the guard
in the helper makes the locking scope match the operation being protected.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
---
Changes in v2:
- Move guard(mutex)() into ads7924_get_adc_result().
- Drop the extra scope from ads7924_read_raw().
drivers/iio/adc/ti-ads7924.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
index bbcc4fc22b6e..5f294595a415 100644
--- a/drivers/iio/adc/ti-ads7924.c
+++ b/drivers/iio/adc/ti-ads7924.c
@@ -12,6 +12,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/init.h>
@@ -198,6 +199,8 @@ static int ads7924_get_adc_result(struct ads7924_data *data,
if (chan->channel < 0 || chan->channel >= ADS7924_CHANNELS)
return -EINVAL;
+ guard(mutex)(&data->lock);
+
if (data->conv_invalid) {
int conv_time;
@@ -227,9 +230,7 @@ static int ads7924_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- mutex_lock(&data->lock);
ret = ads7924_get_adc_result(data, chan, val);
- mutex_unlock(&data->lock);
if (ret < 0)
return ret;
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads7924: Use guard(mutex) in ADC read helper
2026-04-20 11:34 [PATCH v2] iio: adc: ti-ads7924: Use guard(mutex) in ADC read helper Giorgi Tchankvetadze
@ 2026-04-21 14:58 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-04-21 14:58 UTC (permalink / raw)
To: Giorgi Tchankvetadze
Cc: antoniu.miclaus, lars, Michael.Hennerich, dlechner, nuno.sa, andy,
linux-iio, linux-kernel
On Mon, 20 Apr 2026 15:34:45 +0400
Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com> wrote:
> Replace mutex_lock()/mutex_unlock() pair with guard(mutex)()
> and move the lock into ads7924_get_adc_result(). Keeping the guard
> in the helper makes the locking scope match the operation being protected.
>
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Applied.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-21 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 11:34 [PATCH v2] iio: adc: ti-ads7924: Use guard(mutex) in ADC read helper Giorgi Tchankvetadze
2026-04-21 14:58 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox