Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3 0/4] iio: accel: convert to guard(mutex)
@ 2026-03-12  8:19 Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 1/4] iio: accel: bmc150: " Rajveer Chaudhari
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12  8:19 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano
  Cc: linux-iio, linux-kernel, Rajveer Chaudhari

This series converts manual mutex_lock/mutex_unlock pairs to
guard(mutex) in two ADXL accelerometer drivers. Each conversion
also simplifies error handling by removing goto labels and
returning directly on error paths.

v3 : Fixed return statements to make it clear about good/error paths.
indentation fix and reducing code indent -- as suggested by
Jonathan Cameron

Link to v2: https://lore.kernel.org/all/20260309153408.71512-1-
rajveer.chaudhari.linux@gmail.com/

Rajveer Chaudhari (4):
  iio: accel: bmc150: convert to guard(mutex)
  iio: accel: mma8452: convert to guard(mutex)
  iio: accel: mma9551: convert to guard(mutex)
  iio: accel: sca3000: convert to guard(mutex)

 drivers/iio/accel/bmc150-accel-core.c |  22 ++--
 drivers/iio/accel/mma8452.c           |  21 ++--
 drivers/iio/accel/mma9551.c           |  10 +-
 drivers/iio/accel/sca3000.c           | 139 +++++++++++---------------
 4 files changed, 81 insertions(+), 111 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12  8:19 [PATCH v3 0/4] iio: accel: convert to guard(mutex) Rajveer Chaudhari
@ 2026-03-12  8:19 ` Rajveer Chaudhari
  2026-03-12 14:19   ` Andy Shevchenko
  2026-03-12  8:19 ` [PATCH v3 2/4] iio: accel: mma8452: " Rajveer Chaudhari
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12  8:19 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano
  Cc: linux-iio, linux-kernel, Rajveer Chaudhari

Replace manual mutex_lock/mutex_unlock pair with guard(mutex)
in bmc150_accel_buffer_predisable() and
bmc150_accel_buffer_postenable(). This ensures the mutex is
released on all return paths and allows returning directly
without a goto label.

Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
---
v3: stop initialising ret=0 at start, making clear about good path.
moved return ret up into the if (ret) {} block in
bmc150_accel_buffer_postenable().

v2: Cleaned mutex_unlock and goto in
bmc150_accel_buffer_postenable(),
Dropped Header alignment change.
---
 drivers/iio/accel/bmc150-accel-core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 42ccf0316ce5..4772dc6fcee9 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -7,6 +7,7 @@
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
@@ -1480,20 +1481,20 @@ static int bmc150_accel_buffer_preenable(struct iio_dev *indio_dev)
 static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev)
 {
 	struct bmc150_accel_data *data = iio_priv(indio_dev);
-	int ret = 0;
+	int ret;
 
 	if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
 		return 0;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	if (!data->watermark)
-		goto out;
+		return 0;
 
 	ret = bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK,
 					 true);
 	if (ret)
-		goto out;
+		return ret;
 
 	data->fifo_mode = BMC150_ACCEL_FIFO_MODE_FIFO;
 
@@ -1502,12 +1503,10 @@ static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev)
 		data->fifo_mode = 0;
 		bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK,
 					   false);
+		return ret;
 	}
 
-out:
-	mutex_unlock(&data->mutex);
-
-	return ret;
+	return 0;
 }
 
 static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev)
@@ -1517,19 +1516,16 @@ static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev)
 	if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
 		return 0;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	if (!data->fifo_mode)
-		goto out;
+		return 0;
 
 	bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK, false);
 	__bmc150_accel_fifo_flush(indio_dev, BMC150_ACCEL_FIFO_LENGTH, false);
 	data->fifo_mode = 0;
 	bmc150_accel_fifo_set_mode(data);
 
-out:
-	mutex_unlock(&data->mutex);
-
 	return 0;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/4] iio: accel: mma8452: convert to guard(mutex)
  2026-03-12  8:19 [PATCH v3 0/4] iio: accel: convert to guard(mutex) Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 1/4] iio: accel: bmc150: " Rajveer Chaudhari
@ 2026-03-12  8:19 ` Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 3/4] iio: accel: mma9551: " Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 4/4] iio: accel: sca3000: " Rajveer Chaudhari
  3 siblings, 0 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12  8:19 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano
  Cc: linux-iio, linux-kernel, Rajveer Chaudhari

Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in
mma8452_change_config(). This ensures the mutex is
released on all return paths and allows returning directly
without a goto label.

Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
---
v3 : No changes

v2 : Dropped Header alignment change
---
 drivers/iio/accel/mma8452.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 15172ba2972c..09bb205a1b8f 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -20,6 +20,7 @@
 
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/cleanup.h>
 #include <linux/property.h>
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
@@ -597,36 +598,30 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
 	int ret;
 	int is_active;
 
-	mutex_lock(&data->lock);
+	guard(mutex)(&data->lock);
 
 	is_active = mma8452_is_active(data);
-	if (is_active < 0) {
-		ret = is_active;
-		goto fail;
-	}
+	if (is_active < 0)
+		return is_active;
 
 	/* config can only be changed when in standby */
 	if (is_active > 0) {
 		ret = mma8452_standby(data);
 		if (ret < 0)
-			goto fail;
+			return ret;
 	}
 
 	ret = i2c_smbus_write_byte_data(data->client, reg, val);
 	if (ret < 0)
-		goto fail;
+		return ret;
 
 	if (is_active > 0) {
 		ret = mma8452_active(data);
 		if (ret < 0)
-			goto fail;
+			return ret;
 	}
 
-	ret = 0;
-fail:
-	mutex_unlock(&data->lock);
-
-	return ret;
+	return 0;
 }
 
 static int mma8452_set_power_mode(struct mma8452_data *data, u8 mode)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/4] iio: accel: mma9551: convert to guard(mutex)
  2026-03-12  8:19 [PATCH v3 0/4] iio: accel: convert to guard(mutex) Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 1/4] iio: accel: bmc150: " Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 2/4] iio: accel: mma8452: " Rajveer Chaudhari
@ 2026-03-12  8:19 ` Rajveer Chaudhari
  2026-03-12  8:19 ` [PATCH v3 4/4] iio: accel: sca3000: " Rajveer Chaudhari
  3 siblings, 0 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12  8:19 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano
  Cc: linux-iio, linux-kernel, Rajveer Chaudhari

Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in
mma9551_event_handler(). This ensures the mutex is
released on all return paths and allows returning directly
without a goto label.

Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
---
v3: No Changes

v2: Dropped Header alignment change
---
 drivers/iio/accel/mma9551.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c
index 02195deada49..65a913972ce2 100644
--- a/drivers/iio/accel/mma9551.c
+++ b/drivers/iio/accel/mma9551.c
@@ -9,6 +9,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
 #include <linux/iio/iio.h>
@@ -337,7 +338,7 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
 	u16 reg;
 	u8 val;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	for (i = 0; i < 3; i++)
 		if (irq == data->irqs[i]) {
@@ -349,7 +350,7 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
 		/* IRQ was triggered on 4th line, which we don't use. */
 		dev_warn(&data->client->dev,
 			 "irq triggered on unused line %d\n", data->irqs[3]);
-		goto out;
+		return IRQ_HANDLED;
 	}
 
 	switch (mma_axis) {
@@ -373,7 +374,7 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
 	if (ret < 0) {
 		dev_err(&data->client->dev,
 			"error %d reading tilt register in IRQ\n", ret);
-		goto out;
+		return IRQ_HANDLED;
 	}
 
 	iio_push_event(indio_dev,
@@ -381,9 +382,6 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
 					  IIO_EV_TYPE_ROC, IIO_EV_DIR_RISING),
 		       iio_get_time_ns(indio_dev));
 
-out:
-	mutex_unlock(&data->mutex);
-
 	return IRQ_HANDLED;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/4] iio: accel: sca3000: convert to guard(mutex)
  2026-03-12  8:19 [PATCH v3 0/4] iio: accel: convert to guard(mutex) Rajveer Chaudhari
                   ` (2 preceding siblings ...)
  2026-03-12  8:19 ` [PATCH v3 3/4] iio: accel: mma9551: " Rajveer Chaudhari
@ 2026-03-12  8:19 ` Rajveer Chaudhari
  3 siblings, 0 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12  8:19 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano
  Cc: linux-iio, linux-kernel, Rajveer Chaudhari

Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in
sca3000_print_rev(), sca3000_ring_int_process(),
sca3000_read_event_config(), __sca3000_hw_ring_state_set(),
sca3000_hw_ring_preenable(), sca3000_hw_ring_postdisable(),
sca3000_clean_setup(), sca3000_stop_all_interrupts().
This ensures the mutex is released on all return paths and
allows returning directly without a goto label.

Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
---
v3: Fixed return statements to make it clear about good/error path.
Removed Not necessary return statement in sca3000_read_event_config().
Dropped else statement to reduce indent of the code in
sca3000_read_event_config.
Fixed indentation.

v2: Dropped Header alignment change
---
 drivers/iio/accel/sca3000.c | 139 ++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 79 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index 4a827be439a2..2586a72d36aa 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -9,6 +9,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/fs.h>
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/kernel.h>
@@ -424,18 +425,18 @@ static int sca3000_print_rev(struct iio_dev *indio_dev)
 	int ret;
 	struct sca3000_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	ret = sca3000_read_data_short(st, SCA3000_REG_REVID_ADDR, 1);
 	if (ret < 0)
-		goto error_ret;
+		return ret;
+
 	dev_info(&indio_dev->dev,
 		 "sca3000 revision major=%lu, minor=%lu\n",
 		 st->rx[0] & SCA3000_REG_REVID_MAJOR_MASK,
 		 st->rx[0] & SCA3000_REG_REVID_MINOR_MASK);
-error_ret:
-	mutex_unlock(&st->lock);
 
-	return ret;
+	return 0;
 }
 
 static ssize_t
@@ -996,13 +997,14 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret, i, num_available;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	if (val & SCA3000_REG_INT_STATUS_HALF) {
 		ret = sca3000_read_data_short(st, SCA3000_REG_BUF_COUNT_ADDR,
 					      1);
 		if (ret)
-			goto error_ret;
+			return;
+
 		num_available = st->rx[0];
 		/*
 		 * num_available is the total number of samples available
@@ -1011,7 +1013,8 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 		ret = sca3000_read_data(st, SCA3000_REG_RING_OUT_ADDR, st->rx,
 					num_available * 2);
 		if (ret)
-			goto error_ret;
+			return;
+
 		for (i = 0; i < num_available / 3; i++) {
 			/*
 			 * Dirty hack to cover for 11 bit in fifo, 13 bit
@@ -1023,8 +1026,6 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 			iio_push_to_buffers(indio_dev, st->rx + i * 3 * 2);
 		}
 	}
-error_ret:
-	mutex_unlock(&st->lock);
 }
 
 /**
@@ -1110,16 +1111,15 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
 	/* read current value of mode register */
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
-		goto error_ret;
+		return ret;
 
 	switch (chan->channel2) {
 	case IIO_MOD_X_AND_Y_AND_Z:
-		ret = !!(st->rx[0] & SCA3000_REG_MODE_FREE_FALL_DETECT);
-		break;
+		return !!(st->rx[0] & SCA3000_REG_MODE_FREE_FALL_DETECT);
 	case IIO_MOD_X:
 	case IIO_MOD_Y:
 	case IIO_MOD_Z:
@@ -1129,24 +1129,18 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 		 */
 		if ((st->rx[0] & SCA3000_REG_MODE_MODE_MASK)
 		    != SCA3000_REG_MODE_MEAS_MODE_MOT_DET) {
-			ret = 0;
-		} else {
-			ret = sca3000_read_ctrl_reg(st,
-						SCA3000_REG_CTRL_SEL_MD_CTRL);
-			if (ret < 0)
-				goto error_ret;
-			/* only supporting logical or's for now */
-			ret = !!(ret & sca3000_addresses[chan->address][2]);
+			return 0;
 		}
-		break;
+
+		ret = sca3000_read_ctrl_reg(st,
+					SCA3000_REG_CTRL_SEL_MD_CTRL);
+		if (ret < 0)
+			return ret;
+		/* only supporting logical or's for now */
+		return !!(ret & sca3000_addresses[chan->address][2]);
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret;
 }
 
 static int sca3000_freefall_set_state(struct iio_dev *indio_dev, bool state)
@@ -1277,23 +1271,21 @@ int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
-		goto error_ret;
+		return ret;
+
 	if (state) {
 		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
-		ret = sca3000_write_reg(st,
+		return sca3000_write_reg(st,
 			SCA3000_REG_MODE_ADDR,
 			(st->rx[0] | SCA3000_REG_MODE_RING_BUF_ENABLE));
 	} else
-		ret = sca3000_write_reg(st,
+		return sca3000_write_reg(st,
 			SCA3000_REG_MODE_ADDR,
 			(st->rx[0] & ~SCA3000_REG_MODE_RING_BUF_ENABLE));
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret;
 }
 
 /**
@@ -1310,26 +1302,20 @@ static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 	int ret;
 	struct sca3000_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	/* Enable the 50% full interrupt */
 	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
-		goto error_unlock;
+		return ret;
+
 	ret = sca3000_write_reg(st,
 				SCA3000_REG_INT_MASK_ADDR,
 				st->rx[0] | SCA3000_REG_INT_MASK_RING_HALF);
 	if (ret)
-		goto error_unlock;
-
-	mutex_unlock(&st->lock);
+		return ret;
 
 	return __sca3000_hw_ring_state_set(indio_dev, 1);
-
-error_unlock:
-	mutex_unlock(&st->lock);
-
-	return ret;
 }
 
 static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
@@ -1342,17 +1328,15 @@ static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
 		return ret;
 
 	/* Disable the 50% full interrupt */
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
 
 	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
-		goto unlock;
-	ret = sca3000_write_reg(st,
-				SCA3000_REG_INT_MASK_ADDR,
-				st->rx[0] & ~SCA3000_REG_INT_MASK_RING_HALF);
-unlock:
-	mutex_unlock(&st->lock);
-	return ret;
+		return ret;
+
+	return sca3000_write_reg(st,
+				 SCA3000_REG_INT_MASK_ADDR,
+				 st->rx[0] & ~SCA3000_REG_INT_MASK_RING_HALF);
 }
 
 static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
@@ -1372,25 +1356,26 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 {
 	int ret;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	/* Ensure all interrupts have been acknowledged */
 	ret = sca3000_read_data_short(st, SCA3000_REG_INT_STATUS_ADDR, 1);
 	if (ret)
-		goto error_ret;
+		return ret;
 
 	/* Turn off all motion detection channels */
 	ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL);
 	if (ret < 0)
-		goto error_ret;
+		return ret;
 	ret = sca3000_write_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL,
 				     ret & SCA3000_MD_CTRL_PROT_MASK);
 	if (ret)
-		goto error_ret;
+		return ret;
 
 	/* Disable ring buffer */
 	ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL);
 	if (ret < 0)
-		goto error_ret;
+		return ret;
 	ret = sca3000_write_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL,
 				     (ret & SCA3000_REG_OUT_CTRL_PROT_MASK)
 				     | SCA3000_REG_OUT_CTRL_BUF_X_EN
@@ -1398,17 +1383,17 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 				     | SCA3000_REG_OUT_CTRL_BUF_Z_EN
 				     | SCA3000_REG_OUT_CTRL_BUF_DIV_4);
 	if (ret)
-		goto error_ret;
+		return ret;
 	/* Enable interrupts, relevant to mode and set up as active low */
 	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
-		goto error_ret;
+		return ret;
 	ret = sca3000_write_reg(st,
 				SCA3000_REG_INT_MASK_ADDR,
 				(ret & SCA3000_REG_INT_MASK_PROT_MASK)
 				| SCA3000_REG_INT_MASK_ACTIVE_LOW);
 	if (ret)
-		goto error_ret;
+		return ret;
 	/*
 	 * Select normal measurement mode, free fall off, ring off
 	 * Ring in 12 bit mode - it is fine to overwrite reserved bits 3,5
@@ -1416,13 +1401,10 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 	 */
 	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
-		goto error_ret;
-	ret = sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
-				(st->rx[0] & SCA3000_MODE_PROT_MASK));
+		return ret;
 
-error_ret:
-	mutex_unlock(&st->lock);
-	return ret;
+	return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
+				(st->rx[0] & SCA3000_MODE_PROT_MASK));
 }
 
 static const struct iio_info sca3000_info = {
@@ -1504,18 +1486,17 @@ static int 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;
-	ret = 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);
-	return ret;
+		return 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)));
 }
 
 static void sca3000_remove(struct spi_device *spi)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12  8:19 ` [PATCH v3 1/4] iio: accel: bmc150: " Rajveer Chaudhari
@ 2026-03-12 14:19   ` Andy Shevchenko
  2026-03-12 16:27     ` Rajveer Chaudhari
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2026-03-12 14:19 UTC (permalink / raw)
  To: Rajveer Chaudhari
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 01:49:39PM +0530, Rajveer Chaudhari wrote:
> Replace manual mutex_lock/mutex_unlock pair with guard(mutex)
> in bmc150_accel_buffer_predisable() and
> bmc150_accel_buffer_postenable(). This ensures the mutex is
> released on all return paths and allows returning directly
> without a goto label.

> v2: Cleaned mutex_unlock and goto in
> bmc150_accel_buffer_postenable(),


> Dropped Header alignment change.

I don't understand why you can't do that as prerequisite. At some point we
probably go through them to fix, but since the new header is added, it makes
sense to put it to the proper order.

Same comment to other patches in the series.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12 14:19   ` Andy Shevchenko
@ 2026-03-12 16:27     ` Rajveer Chaudhari
  2026-03-12 16:47       ` Waqar Hameed
  2026-03-13  8:56       ` Andy Shevchenko
  0 siblings, 2 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12 16:27 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 7:49 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> I don't understand why you can't do that as prerequisite. At some point we
> probably go through them to fix, but since the new header is added, it makes
> sense to put it to the proper order.

Hello Andy

Thanks for the review, as Waqar Hameed said earlier to not change
anything until they have
a consensus here.
Ref Link: https://lore.kernel.org/all/pndwlzk51j3.a.out@axis.com/

Do you want me to order the headers now in the new version?, I would
be happy to do that.

With Best Regards,
Rajveer Chaudhari

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12 16:27     ` Rajveer Chaudhari
@ 2026-03-12 16:47       ` Waqar Hameed
  2026-03-12 17:31         ` Rajveer Chaudhari
  2026-03-13  8:56       ` Andy Shevchenko
  1 sibling, 1 reply; 12+ messages in thread
From: Waqar Hameed @ 2026-03-12 16:47 UTC (permalink / raw)
  To: Rajveer Chaudhari
  Cc: Andy Shevchenko, jic23, dlechner, nuno.sa, andy, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 21:57 +0530 Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com> wrote:

> On Thu, Mar 12, 2026 at 7:49 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
>>
>> I don't understand why you can't do that as prerequisite. At some point we
>> probably go through them to fix, but since the new header is added, it makes
>> sense to put it to the proper order.
>
> Hello Andy
>
> Thanks for the review, as Waqar Hameed said earlier to not change
> anything until they have
> a consensus here.
> Ref Link: https://lore.kernel.org/all/pndwlzk51j3.a.out@axis.com/
>
> Do you want me to order the headers now in the new version?, I would
> be happy to do that.

I think "consensus" was met with Jonathan's mail [1]. You must've read
it since you replied to it, or?

As I said in my first comment: put the changes into separate patches
(sorting the headers is one patch and the `guard(mutex)` another). Then
put all of them in *one* patch series. I hope this is clear enough...

[1] https://lore.kernel.org/lkml/20260309191504.616a9bd3@jic23-huawei/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12 16:47       ` Waqar Hameed
@ 2026-03-12 17:31         ` Rajveer Chaudhari
  2026-03-13 10:28           ` Waqar Hameed
  0 siblings, 1 reply; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-12 17:31 UTC (permalink / raw)
  To: Waqar Hameed
  Cc: Andy Shevchenko, jic23, dlechner, nuno.sa, andy, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 10:17 PM Waqar Hameed <waqar.hameed@axis.com> wrote:
>
> I think "consensus" was met with Jonathan's mail [1]. You must've read
> it since you replied to it, or?

Yes i have read that reply, i am sorry i misunderstood your statement i thought
it would be an update in styling rules or something then i will have to act.
Now i get it.

> As I said in my first comment: put the changes into separate patches
> (sorting the headers is one patch and the `guard(mutex)` another). Then
> put all of them in *one* patch series. I hope this is clear enough...

Yes it is clear, i will add separate patches in the series to put headers in
alphabetical order.

Thankyou,
Rajveer Chaudhari

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12 16:27     ` Rajveer Chaudhari
  2026-03-12 16:47       ` Waqar Hameed
@ 2026-03-13  8:56       ` Andy Shevchenko
  1 sibling, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2026-03-13  8:56 UTC (permalink / raw)
  To: Rajveer Chaudhari
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 09:57:33PM +0530, Rajveer Chaudhari wrote:
> On Thu, Mar 12, 2026 at 7:49 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> >
> > I don't understand why you can't do that as prerequisite. At some point we
> > probably go through them to fix, but since the new header is added, it makes
> > sense to put it to the proper order.
> 
> Thanks for the review, as Waqar Hameed said earlier to not change
> anything until they have
> a consensus here.
> Ref Link: https://lore.kernel.org/all/pndwlzk51j3.a.out@axis.com/
> 
> Do you want me to order the headers now in the new version?, I would
> be happy to do that.

In IIO we want to have the unified style across the drivers. WRT header
inclusions there are several expectations:
- headers are sorted
- IWYU principle is followed
- the IIO (and rarely some others) are grouped

OTOH we don't want to see the patch just for the same of this unification
as it adds just a churn (if driver is not under active development, it's
better to leave it alone for the maintainer's decision). Since you have
other patches in your series which introduce a new header, it's okay to
have a prerequisite to fix the ordering issues.


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-12 17:31         ` Rajveer Chaudhari
@ 2026-03-13 10:28           ` Waqar Hameed
  2026-03-13 10:48             ` Rajveer Chaudhari
  0 siblings, 1 reply; 12+ messages in thread
From: Waqar Hameed @ 2026-03-13 10:28 UTC (permalink / raw)
  To: Rajveer Chaudhari
  Cc: Andy Shevchenko, jic23, dlechner, nuno.sa, andy, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Thu, Mar 12, 2026 at 23:01 +0530 Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com> wrote:

> On Thu, Mar 12, 2026 at 10:17 PM Waqar Hameed <waqar.hameed@axis.com> wrote:
>>
>> I think "consensus" was met with Jonathan's mail [1]. You must've read
>> it since you replied to it, or?
>
> Yes i have read that reply, i am sorry i misunderstood your statement i thought
> it would be an update in styling rules or something then i will have to act.
> Now i get it.

[...]

No worries! As I said before, it's not always easy navigating the
different sub-systems in kernel development. A future tip is to see how
most other drivers are written, they usually tend to follow the guide
lines. If not, one can fix them on the go, just like here :)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
  2026-03-13 10:28           ` Waqar Hameed
@ 2026-03-13 10:48             ` Rajveer Chaudhari
  0 siblings, 0 replies; 12+ messages in thread
From: Rajveer Chaudhari @ 2026-03-13 10:48 UTC (permalink / raw)
  To: Waqar Hameed
  Cc: Andy Shevchenko, jic23, dlechner, nuno.sa, andy, linusw,
	sakari.ailus, harshit.m.mogalapalli, antoniu.miclaus,
	andrew.ijano, linux-iio, linux-kernel

On Fri, Mar 13, 2026 at 3:58 PM Waqar Hameed <waqar.hameed@axis.com> wrote:
>
> No worries! As I said before, it's not always easy navigating the
> different sub-systems in kernel development. A future tip is to see how
> most other drivers are written, they usually tend to follow the guide
> lines. If not, one can fix them on the go, just like here :)

Yesss got it!

Thank you :)

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-03-13 10:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12  8:19 [PATCH v3 0/4] iio: accel: convert to guard(mutex) Rajveer Chaudhari
2026-03-12  8:19 ` [PATCH v3 1/4] iio: accel: bmc150: " Rajveer Chaudhari
2026-03-12 14:19   ` Andy Shevchenko
2026-03-12 16:27     ` Rajveer Chaudhari
2026-03-12 16:47       ` Waqar Hameed
2026-03-12 17:31         ` Rajveer Chaudhari
2026-03-13 10:28           ` Waqar Hameed
2026-03-13 10:48             ` Rajveer Chaudhari
2026-03-13  8:56       ` Andy Shevchenko
2026-03-12  8:19 ` [PATCH v3 2/4] iio: accel: mma8452: " Rajveer Chaudhari
2026-03-12  8:19 ` [PATCH v3 3/4] iio: accel: mma9551: " Rajveer Chaudhari
2026-03-12  8:19 ` [PATCH v3 4/4] iio: accel: sca3000: " Rajveer Chaudhari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox