[PATCH v5 next 5/7] iio: sca3000: use guard(mutex) to simplify return paths

Harshit Mogalapalli posted 7 patches 4 days, 17 hours ago
[PATCH v5 next 5/7] iio: sca3000: use guard(mutex) to simplify return paths
Posted by Harshit Mogalapalli 4 days, 17 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>
---
v4->v5: rebase it accordingly as we didn't change label "error_ret" in
the previous patch.
---
 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 d3e2a981874d..56ff646684c0 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>
@@ -1439,17 +1440,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 error_ret;
+		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)));
-error_ret:
-	mutex_unlock(&st->lock);
 }
 
 static int sca3000_probe(struct spi_device *spi)
-- 
2.47.3
Re: [PATCH v5 next 5/7] iio: sca3000: use guard(mutex) to simplify return paths
Posted by Andy Shevchenko 4 days, 14 hours ago
On Thu, Feb 05, 2026 at 05:12:11AM -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>

> ---
> v4->v5: rebase it accordingly as we didn't change label "error_ret" in
> the previous patch.

I hope you see the difference and how the whole series gets better.

> ---

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v5 next 5/7] iio: sca3000: use guard(mutex) to simplify return paths
Posted by Harshit Mogalapalli 4 days, 13 hours ago
Hi Andy,

On 05/02/26 21:56, Andy Shevchenko wrote:
> On Thu, Feb 05, 2026 at 05:12:11AM -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>
> 
>> ---
>> v4->v5: rebase it accordingly as we didn't change label "error_ret" in
>> the previous patch.
> 
> I hope you see the difference and how the whole series gets better.
> 

Yes I do, thank you very much for the guidance on this :)


Thanks,
Harshit
>> ---
>