From: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
To: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, waqar.hameed@axis.com, linusw@kernel.org,
sakari.ailus@linux.intel.com, harshit.m.mogalapalli@oracle.com,
antoniu.miclaus@analog.com, andrew.ijano@gmail.com
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
Subject: [PATCH v3 1/4] iio: accel: bmc150: convert to guard(mutex)
Date: Thu, 12 Mar 2026 13:49:39 +0530 [thread overview]
Message-ID: <20260312081942.23858-2-rajveer.chaudhari.linux@gmail.com> (raw)
In-Reply-To: <20260312081942.23858-1-rajveer.chaudhari.linux@gmail.com>
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
next prev parent reply other threads:[~2026-03-12 8:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 8:19 [PATCH v3 0/4] iio: accel: " Rajveer Chaudhari
2026-03-12 8:19 ` Rajveer Chaudhari [this message]
2026-03-12 14:19 ` [PATCH v3 1/4] iio: accel: bmc150: " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312081942.23858-2-rajveer.chaudhari.linux@gmail.com \
--to=rajveer.chaudhari.linux@gmail.com \
--cc=andrew.ijano@gmail.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=dlechner@baylibre.com \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=jic23@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=sakari.ailus@linux.intel.com \
--cc=waqar.hameed@axis.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®