* [PATCH v4 0/2] iio: accel: convert to guard(mutex) @ 2026-03-07 11:49 Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 1/2] iio: accel: adxl313: " Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 2/2] iio: accel: adxl372: " Rajveer Chaudhari 0 siblings, 2 replies; 4+ messages in thread From: Rajveer Chaudhari @ 2026-03-07 11:49 UTC (permalink / raw) To: lucas.p.stankus, lars, Michael.Hennerich, jic23, nuno.sa, andy, puranjay, dlechner 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. adxl355 was considered but dropped as guard(mutex) leads to code duplication due to the STANDBY/MEASUREMENT op_mode pattern, making it less readable than the original code. Ref to v3: [PATCH v3 0/3] iio: accel: convert to guard(mutex) Rajveer Chaudhari (2): iio: accel: adxl313: convert to guard(mutex) iio: accel: adxl372: convert to guard(mutex) drivers/iio/accel/adxl313_core.c | 11 ++++------- drivers/iio/accel/adxl372.c | 13 +++++-------- 2 files changed, 9 insertions(+), 15 deletions(-) -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 1/2] iio: accel: adxl313: convert to guard(mutex) 2026-03-07 11:49 [PATCH v4 0/2] iio: accel: convert to guard(mutex) Rajveer Chaudhari @ 2026-03-07 11:49 ` Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 2/2] iio: accel: adxl372: " Rajveer Chaudhari 1 sibling, 0 replies; 4+ messages in thread From: Rajveer Chaudhari @ 2026-03-07 11:49 UTC (permalink / raw) To: lucas.p.stankus, lars, Michael.Hennerich, jic23, nuno.sa, andy, puranjay, dlechner Cc: linux-iio, linux-kernel, Rajveer Chaudhari Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in adxl313_read_axis(). 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> --- v4: Keep ret declaration at top of function. v3: Return directly from regmap_bulk_read error path. v2: Split into separate patch per driver. --- drivers/iio/accel/adxl313_core.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c index 9f5d4d2cb325..084037c89ad3 100644 --- a/drivers/iio/accel/adxl313_core.c +++ b/drivers/iio/accel/adxl313_core.c @@ -8,6 +8,7 @@ */ #include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/overflow.h> @@ -356,19 +357,15 @@ static int adxl313_read_axis(struct adxl313_data *data, { int ret; - mutex_lock(&data->lock); + guard(mutex)(&data->lock); ret = regmap_bulk_read(data->regmap, ADXL313_REG_DATA_AXIS(chan->address), &data->transf_buf, sizeof(data->transf_buf)); if (ret) - goto unlock_ret; - - ret = le16_to_cpu(data->transf_buf); + return ret; -unlock_ret: - mutex_unlock(&data->lock); - return ret; + return le16_to_cpu(data->transf_buf); } static int adxl313_read_freq_avail(struct iio_dev *indio_dev, -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 2/2] iio: accel: adxl372: convert to guard(mutex) 2026-03-07 11:49 [PATCH v4 0/2] iio: accel: convert to guard(mutex) Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 1/2] iio: accel: adxl313: " Rajveer Chaudhari @ 2026-03-07 11:49 ` Rajveer Chaudhari 2026-03-07 17:11 ` Jonathan Cameron 1 sibling, 1 reply; 4+ messages in thread From: Rajveer Chaudhari @ 2026-03-07 11:49 UTC (permalink / raw) To: lucas.p.stankus, lars, Michael.Hennerich, jic23, nuno.sa, andy, puranjay, dlechner Cc: linux-iio, linux-kernel, Rajveer Chaudhari Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in adxl372_write_threshold_value(). 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> --- v4: Changelog moved below --- as requested by Jonathan Cameron. v3: Return directly from error path without goto. v2: Split into separate patch per driver. --- drivers/iio/accel/adxl372.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index 28a8793a53b6..4bf8656991ea 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -7,6 +7,7 @@ #include <linux/bitfield.h> #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/module.h> @@ -336,18 +337,14 @@ static ssize_t adxl372_write_threshold_value(struct iio_dev *indio_dev, unsigned struct adxl372_state *st = iio_priv(indio_dev); int ret; - mutex_lock(&st->threshold_m); + guard(mutex)(&st->threshold_m); + ret = regmap_write(st->regmap, addr, ADXL372_THRESH_VAL_H_SEL(threshold)); if (ret < 0) - goto unlock; + return ret; - ret = regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5), + return regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5), ADXL372_THRESH_VAL_L_SEL(threshold) << 5); - -unlock: - mutex_unlock(&st->threshold_m); - - return ret; } static int adxl372_read_axis(struct adxl372_state *st, u8 addr) -- 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 2/2] iio: accel: adxl372: convert to guard(mutex) 2026-03-07 11:49 ` [PATCH v4 2/2] iio: accel: adxl372: " Rajveer Chaudhari @ 2026-03-07 17:11 ` Jonathan Cameron 0 siblings, 0 replies; 4+ messages in thread From: Jonathan Cameron @ 2026-03-07 17:11 UTC (permalink / raw) To: Rajveer Chaudhari Cc: lucas.p.stankus, lars, Michael.Hennerich, nuno.sa, andy, puranjay, dlechner, linux-iio, linux-kernel On Sat, 7 Mar 2026 17:19:12 +0530 Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com> wrote: > Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in > adxl372_write_threshold_value(). 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> Series applied. One small tweak mentioned below. Applied to the testing branch of iio.git where the bots poke at it briefly before I push it out as togreg which linux-next picks up. Thanks, Jonathan > --- > v4: Changelog moved below --- as requested by Jonathan Cameron. > v3: Return directly from error path without goto. > v2: Split into separate patch per driver. > --- > drivers/iio/accel/adxl372.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c > index 28a8793a53b6..4bf8656991ea 100644 > --- a/drivers/iio/accel/adxl372.c > +++ b/drivers/iio/accel/adxl372.c > @@ -7,6 +7,7 @@ > > #include <linux/bitfield.h> > #include <linux/bitops.h> > +#include <linux/cleanup.h> > #include <linux/interrupt.h> > #include <linux/irq.h> > #include <linux/module.h> > @@ -336,18 +337,14 @@ static ssize_t adxl372_write_threshold_value(struct iio_dev *indio_dev, unsigned > struct adxl372_state *st = iio_priv(indio_dev); > int ret; > > - mutex_lock(&st->threshold_m); > + guard(mutex)(&st->threshold_m); > + > ret = regmap_write(st->regmap, addr, ADXL372_THRESH_VAL_H_SEL(threshold)); > if (ret < 0) > - goto unlock; > + return ret; > > - ret = regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5), > + return regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5), > ADXL372_THRESH_VAL_L_SEL(threshold) << 5); I'd expect a minor indent update to be needed here. 1 more space. > - > -unlock: > - mutex_unlock(&st->threshold_m); > - > - return ret; > } > > static int adxl372_read_axis(struct adxl372_state *st, u8 addr) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-07 17:11 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-03-07 11:49 [PATCH v4 0/2] iio: accel: convert to guard(mutex) Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 1/2] iio: accel: adxl313: " Rajveer Chaudhari 2026-03-07 11:49 ` [PATCH v4 2/2] iio: accel: adxl372: " Rajveer Chaudhari 2026-03-07 17:11 ` Jonathan Cameron
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®