[PATCH v4 next 4/6] iio: sca3000: use guard(mutex) to simplify return paths

Harshit Mogalapalli posted 6 patches 5 days, 19 hours ago
There is a newer version of this series
[PATCH v4 next 4/6] iio: sca3000: use guard(mutex) to simplify return paths
Posted by Harshit Mogalapalli 5 days, 19 hours ago
Switch sca3000_stop_all_interrupts() to use guard(mutex) to simplify the
error paths without needing a goto.

Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
V3->V4: Move this patch earlier this simplifies a fucntion involved in
the movement.[Thanks to Andy for the suggestion]
---
 drivers/iio/accel/sca3000.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index f9680071bbbe..a46990453ed0 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -7,6 +7,7 @@
  * See industrialio/accels/sca3000.h for comments.
  */
 
+#include <linux/cleanup.h>
 #include <linux/interrupt.h>
 #include <linux/fs.h>
 #include <linux/device.h>
@@ -1499,17 +1500,17 @@ static void sca3000_stop_all_interrupts(struct sca3000_state *st)
 {
 	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
-		goto out_unlock;
+		return;
+
 	sca3000_write_reg(st, SCA3000_REG_INT_MASK_ADDR,
 			  (st->rx[0] &
 			   ~(SCA3000_REG_INT_MASK_RING_THREE_QUARTER |
 			     SCA3000_REG_INT_MASK_RING_HALF |
 			     SCA3000_REG_INT_MASK_ALL_INTS)));
-out_unlock:
-	mutex_unlock(&st->lock);
 }
 
 static void sca3000_remove(struct spi_device *spi)
-- 
2.47.3
Re: [PATCH v4 next 4/6] iio: sca3000: use guard(mutex) to simplify return paths
Posted by Andy Shevchenko 5 days, 16 hours ago
On Tue, Feb 03, 2026 at 10:11:59PM -0800, Harshit Mogalapalli wrote:
> Switch sca3000_stop_all_interrupts() to use guard(mutex) to simplify the
> error paths without needing a goto.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko