[PATCH] iio: adc: ti-ads1015: Use scoped_guard() in trigger handler
From: Tabrez Ahmed
Date: Sat Feb 21 2026 - 09:25:20 EST
Replace the manual mutex_lock() and mutex_unlock() calls with the
scoped_guard() macro in ads1015_trigger_handler(). This simplifies
the locking logic by ensuring the mutex is always properly released
out of scope, while maintaining the trigger notification on the
error path.
Signed-off-by: Tabrez Ahmed <tabreztalks@xxxxxxxxx>
---
Compile-tested only.
drivers/iio/adc/ti-ads1015.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index f2a93c63ca14..582d30c07874 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -451,18 +451,16 @@ static irqreturn_t ads1015_trigger_handler(int irq, void *p)
} scan = { };
int chan, ret, res;
- mutex_lock(&data->lock);
- chan = find_first_bit(indio_dev->active_scan_mask,
- iio_get_masklength(indio_dev));
- ret = ads1015_get_adc_result(data, chan, &res);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- goto err;
+ scoped_guard(mutex, &data->lock) {
+ chan = find_first_bit(indio_dev->active_scan_mask,
+ iio_get_masklength(indio_dev));
+ ret = ads1015_get_adc_result(data, chan, &res);
+ if (ret < 0)
+ goto err;
+
+ scan.chan = res;
}
- scan.chan = res;
- mutex_unlock(&data->lock);
-
iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan),
iio_get_time_ns(indio_dev));
--
2.43.0