public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: dac: m62332: Use guard(mutex) for locking
@ 2026-04-14 23:39 Erick Henrique
  2026-04-15 10:20 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Erick Henrique @ 2026-04-14 23:39 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy; +Cc: Erick Henrique, linux-iio

Replace mutex_lock()/mutex_unlock() calls with guard(mutex)() to
simplify locking and make cleanup automatic when the lock goes out
of scope.

Signed-off-by: Erick Henrique <erick.henrique.rodrigues@usp.br>
---
 drivers/iio/dac/m62332.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/dac/m62332.c b/drivers/iio/dac/m62332.c
index 3497513854d7..233a179d234b 100644
--- a/drivers/iio/dac/m62332.c
+++ b/drivers/iio/dac/m62332.c
@@ -41,33 +41,27 @@ static int m62332_set_value(struct iio_dev *indio_dev, u8 val, int channel)
 	outbuf[0] = channel;
 	outbuf[1] = val;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	if (val) {
 		res = regulator_enable(data->vcc);
 		if (res)
-			goto out;
+			return res;
 	}
 
 	res = i2c_master_send(client, outbuf, ARRAY_SIZE(outbuf));
 	if (res >= 0 && res != ARRAY_SIZE(outbuf))
 		res = -EIO;
 	if (res < 0)
-		goto out;
+		return res;
 
 	data->raw[channel] = val;
 
 	if (!val)
 		regulator_disable(data->vcc);
 
-	mutex_unlock(&data->mutex);
-
 	return 0;
 
-out:
-	mutex_unlock(&data->mutex);
-
-	return res;
 }
 
 static int m62332_read_raw(struct iio_dev *indio_dev,
-- 
2.51.0


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

end of thread, other threads:[~2026-04-19 13:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 23:39 [PATCH] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
2026-04-15 10:20 ` Andy Shevchenko
2026-04-15 23:01 ` [PATCH v2] " Erick Henrique
2026-04-17  7:58   ` Andy Shevchenko
2026-04-17  7:59     ` Andy Shevchenko
2026-04-18 13:03 ` [PATCH v3 0/2] " Erick Henrique
2026-04-18 13:03   ` [PATCH v3 1/2] iio: dac: m62332: Clean up header includes Erick Henrique
2026-04-19 12:16     ` Jonathan Cameron
2026-04-18 13:03   ` [PATCH v3 2/2] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
2026-04-19 12:17     ` Jonathan Cameron
2026-04-19 13:49     ` Jonathan Cameron
2026-04-19 12:11   ` [PATCH v3 0/2] " Jonathan Cameron

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