* [PATCH 0/2] iio: dac: ltc2688: minor cleanups
@ 2025-09-23 8:41 Nuno Sá via B4 Relay
2025-09-23 8:41 ` [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init() Nuno Sá via B4 Relay
2025-09-23 8:41 ` [PATCH 2/2] iio: dac: ltc2688: use the auto lock API Nuno Sá via B4 Relay
0 siblings, 2 replies; 6+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-09-23 8:41 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron, David Lechner, Andy Shevchenko
Simple series to improve locking and mutex initialization.
---
Nuno Sá (2):
iio: dac: ltc2688: make use of devm_mutex_init()
iio: dac: ltc2688: use the auto lock API
drivers/iio/dac/ltc2688.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
---
base-commit: 411e8b72c181e4f49352c12ced0fd8426eb683aa
change-id: 20250923-dev-ltc2688-minor-0a68e956b098
--
Thanks!
- Nuno Sá
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init()
2025-09-23 8:41 [PATCH 0/2] iio: dac: ltc2688: minor cleanups Nuno Sá via B4 Relay
@ 2025-09-23 8:41 ` Nuno Sá via B4 Relay
2025-09-27 17:57 ` Jonathan Cameron
2025-09-23 8:41 ` [PATCH 2/2] iio: dac: ltc2688: use the auto lock API Nuno Sá via B4 Relay
1 sibling, 1 reply; 6+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-09-23 8:41 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron, David Lechner, Andy Shevchenko
From: Nuno Sá <nuno.sa@analog.com>
Use devm_mutex_init() since it brings some benefits when
CONFIG_DEBUG_MUTEXES is enabled.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/dac/ltc2688.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/dac/ltc2688.c b/drivers/iio/dac/ltc2688.c
index 7a2ee26a7d68730fe90d9cc91ea764f05eb61791..57028d422868ec48e6900ef1cc4be6dee9cd4547 100644
--- a/drivers/iio/dac/ltc2688.c
+++ b/drivers/iio/dac/ltc2688.c
@@ -953,7 +953,9 @@ static int ltc2688_probe(struct spi_device *spi)
/* Just write this once. No need to do it in every regmap read. */
st->tx_data[3] = LTC2688_CMD_NOOP;
- mutex_init(&st->lock);
+ ret = devm_mutex_init(dev, &st->lock);
+ if (ret)
+ return ret;
st->regmap = devm_regmap_init(dev, <c2688_regmap_bus, st,
<c2688_regmap_config);
--
2.51.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] iio: dac: ltc2688: use the auto lock API
2025-09-23 8:41 [PATCH 0/2] iio: dac: ltc2688: minor cleanups Nuno Sá via B4 Relay
2025-09-23 8:41 ` [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init() Nuno Sá via B4 Relay
@ 2025-09-23 8:41 ` Nuno Sá via B4 Relay
2025-09-27 17:56 ` Jonathan Cameron
1 sibling, 1 reply; 6+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-09-23 8:41 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron, David Lechner, Andy Shevchenko
From: Nuno Sá <nuno.sa@analog.com>
Make use of the cleanup API so that we can simplify some code paths.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/dac/ltc2688.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/dac/ltc2688.c b/drivers/iio/dac/ltc2688.c
index 57028d422868ec48e6900ef1cc4be6dee9cd4547..628e96e20375c06bffe16878fc90cfdde99ae565 100644
--- a/drivers/iio/dac/ltc2688.c
+++ b/drivers/iio/dac/ltc2688.c
@@ -6,6 +6,7 @@
*/
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
@@ -208,12 +209,12 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
code = FIELD_PREP(LTC2688_DITHER_RAW_MASK, code);
}
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
/* select the correct input register to read from */
ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
input << chan);
if (ret)
- goto out_unlock;
+ return ret;
/*
* If in dither/toggle mode the dac should be updated by an
@@ -224,10 +225,7 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
else
reg = LTC2688_CMD_CH_CODE(chan);
- ret = regmap_write(st->regmap, reg, code);
-out_unlock:
- mutex_unlock(&st->lock);
- return ret;
+ return regmap_write(st->regmap, reg, code);
}
static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
@@ -236,15 +234,15 @@ static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
struct ltc2688_chan *c = &st->channels[chan];
int ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
input << chan);
if (ret)
- goto out_unlock;
+ return ret;
ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code);
-out_unlock:
- mutex_unlock(&st->lock);
+ if (ret)
+ return ret;
if (!c->toggle_chan && input == LTC2688_INPUT_B)
*code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code);
@@ -359,15 +357,13 @@ static ssize_t ltc2688_dither_toggle_set(struct iio_dev *indio_dev,
if (ret)
return ret;
- mutex_lock(&st->lock);
+ guard(mutex)(&st->lock);
ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN,
BIT(chan->channel), en << chan->channel);
if (ret)
- goto out_unlock;
+ return ret;
c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT;
-out_unlock:
- mutex_unlock(&st->lock);
return ret ?: len;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] iio: dac: ltc2688: use the auto lock API
2025-09-23 8:41 ` [PATCH 2/2] iio: dac: ltc2688: use the auto lock API Nuno Sá via B4 Relay
@ 2025-09-27 17:56 ` Jonathan Cameron
2025-09-29 5:41 ` Nuno Sá
0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2025-09-27 17:56 UTC (permalink / raw)
To: Nuno Sá via B4 Relay
Cc: nuno.sa, linux-iio, David Lechner, Andy Shevchenko
On Tue, 23 Sep 2025 09:41:48 +0100
Nuno Sá via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
> From: Nuno Sá <nuno.sa@analog.com>
>
> Make use of the cleanup API so that we can simplify some code paths.
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
> drivers/iio/dac/ltc2688.c | 24 ++++++++++--------------
This enables a few related simplifications that should be in this patch as well.
> static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
> @@ -236,15 +234,15 @@ static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
> struct ltc2688_chan *c = &st->channels[chan];
> int ret;
>
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
> ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
> input << chan);
> if (ret)
> - goto out_unlock;
> + return ret;
>
> ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code);
> -out_unlock:
> - mutex_unlock(&st->lock);
> + if (ret)
> + return ret;
>
> if (!c->toggle_chan && input == LTC2688_INPUT_B)
> *code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code);
There is a return ret later in this function that can be return 0;
> @@ -359,15 +357,13 @@ static ssize_t ltc2688_dither_toggle_set(struct iio_dev *indio_dev,
> if (ret)
> return ret;
>
> - mutex_lock(&st->lock);
> + guard(mutex)(&st->lock);
> ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN,
> BIT(chan->channel), en << chan->channel);
> if (ret)
> - goto out_unlock;
> + return ret;
>
> c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT;
> -out_unlock:
> - mutex_unlock(&st->lock);
>
> return ret ?: len;
return len; as can't get here with non zero ret.
> }
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init()
2025-09-23 8:41 ` [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init() Nuno Sá via B4 Relay
@ 2025-09-27 17:57 ` Jonathan Cameron
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2025-09-27 17:57 UTC (permalink / raw)
To: Nuno Sá via B4 Relay
Cc: nuno.sa, linux-iio, David Lechner, Andy Shevchenko
On Tue, 23 Sep 2025 09:41:47 +0100
Nuno Sá via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
> From: Nuno Sá <nuno.sa@analog.com>
>
> Use devm_mutex_init() since it brings some benefits when
> CONFIG_DEBUG_MUTEXES is enabled.
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Applied.
> ---
> drivers/iio/dac/ltc2688.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/dac/ltc2688.c b/drivers/iio/dac/ltc2688.c
> index 7a2ee26a7d68730fe90d9cc91ea764f05eb61791..57028d422868ec48e6900ef1cc4be6dee9cd4547 100644
> --- a/drivers/iio/dac/ltc2688.c
> +++ b/drivers/iio/dac/ltc2688.c
> @@ -953,7 +953,9 @@ static int ltc2688_probe(struct spi_device *spi)
>
> /* Just write this once. No need to do it in every regmap read. */
> st->tx_data[3] = LTC2688_CMD_NOOP;
> - mutex_init(&st->lock);
> + ret = devm_mutex_init(dev, &st->lock);
> + if (ret)
> + return ret;
>
> st->regmap = devm_regmap_init(dev, <c2688_regmap_bus, st,
> <c2688_regmap_config);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] iio: dac: ltc2688: use the auto lock API
2025-09-27 17:56 ` Jonathan Cameron
@ 2025-09-29 5:41 ` Nuno Sá
0 siblings, 0 replies; 6+ messages in thread
From: Nuno Sá @ 2025-09-29 5:41 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá via B4 Relay
Cc: nuno.sa, linux-iio, David Lechner, Andy Shevchenko
On Sat, 2025-09-27 at 18:56 +0100, Jonathan Cameron wrote:
> On Tue, 23 Sep 2025 09:41:48 +0100
> Nuno Sá via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
>
> > From: Nuno Sá <nuno.sa@analog.com>
> >
> > Make use of the cleanup API so that we can simplify some code paths.
> >
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > ---
> > drivers/iio/dac/ltc2688.c | 24 ++++++++++--------------
>
> This enables a few related simplifications that should be in this patch as well.
Yes, both make sense.
- Nuno Sá
>
> > static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
> > @@ -236,15 +234,15 @@ static int ltc2688_dac_code_read(struct ltc2688_state *st,
> > u32 chan, u32 input,
> > struct ltc2688_chan *c = &st->channels[chan];
> > int ret;
> >
> > - mutex_lock(&st->lock);
> > + guard(mutex)(&st->lock);
> > ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
> > input << chan);
> > if (ret)
> > - goto out_unlock;
> > + return ret;
> >
> > ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code);
> > -out_unlock:
> > - mutex_unlock(&st->lock);
> > + if (ret)
> > + return ret;
> >
> > if (!c->toggle_chan && input == LTC2688_INPUT_B)
> > *code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code);
>
> There is a return ret later in this function that can be return 0;
>
> > @@ -359,15 +357,13 @@ static ssize_t ltc2688_dither_toggle_set(struct iio_dev
> > *indio_dev,
> > if (ret)
> > return ret;
> >
> > - mutex_lock(&st->lock);
> > + guard(mutex)(&st->lock);
> > ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN,
> > BIT(chan->channel), en << chan->channel);
> > if (ret)
> > - goto out_unlock;
> > + return ret;
> >
> > c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT;
> > -out_unlock:
> > - mutex_unlock(&st->lock);
> >
> > return ret ?: len;
> return len; as can't get here with non zero ret.
>
> > }
> >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-29 6:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 8:41 [PATCH 0/2] iio: dac: ltc2688: minor cleanups Nuno Sá via B4 Relay
2025-09-23 8:41 ` [PATCH 1/2] iio: dac: ltc2688: make use of devm_mutex_init() Nuno Sá via B4 Relay
2025-09-27 17:57 ` Jonathan Cameron
2025-09-23 8:41 ` [PATCH 2/2] iio: dac: ltc2688: use the auto lock API Nuno Sá via B4 Relay
2025-09-27 17:56 ` Jonathan Cameron
2025-09-29 5:41 ` Nuno Sá
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).