Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex)
@ 2026-06-28  3:48 Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 1/3] iio: dac: m62332: Sort header includes alphabetically Erick Henrique
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Erick Henrique @ 2026-06-28  3:48 UTC (permalink / raw)
  To: jic23
  Cc: andriy.shevchenko, andy, dlechner, nuno.sa, joshua.crofts1,
	linux-iio, Erick Henrique

This series cleans up the m62332 header includes and converts its locking
to guard(mutex).

Changes in v5:
- 3/3: add an explicit #include <linux/cleanup.h> for guard(), instead of
  relying on it being pulled in transitively via mutex.h (Joshua Crofts).
- Picked up Reviewed-by from Joshua Crofts on 1/3 and 2/3.

Changes in v4:
- Split the include cleanup in two: 1/3 only re-sorts the existing
  includes; 2/3 does the IWYU add/remove (per Jonathan Cameron).
- 2/3: drop the unused slab.h and add the specific headers the file uses.
- 3/3 (guard(mutex)): unchanged from v3.

v4: https://lore.kernel.org/r/20260627132530.96680-1-erick.henrique.rodrigues@usp.br
v3: https://lore.kernel.org/r/20260418130322.106769-1-erick.henrique.rodrigues@usp.br

Erick Henrique (3):
  iio: dac: m62332: Sort header includes alphabetically
  iio: dac: m62332: Clean up header includes
  iio: dac: m62332: Use guard(mutex) for locking

 drivers/iio/dac/m62332.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)


base-commit: 4b570552ea4788d49373d3e31c5a802210f4ac45
-- 
2.51.0


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

* [PATCH v5 1/3] iio: dac: m62332: Sort header includes alphabetically
  2026-06-28  3:48 [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Erick Henrique
@ 2026-06-28  3:48 ` Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 2/3] iio: dac: m62332: Clean up header includes Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
  2 siblings, 0 replies; 5+ messages in thread
From: Erick Henrique @ 2026-06-28  3:48 UTC (permalink / raw)
  To: jic23
  Cc: andriy.shevchenko, andy, dlechner, nuno.sa, joshua.crofts1,
	linux-iio, Erick Henrique

Sort the existing header includes alphabetically within their groups.
No headers are added or removed; this only reorders them so the
following include cleanup is easier to review.

Signed-off-by: Erick Henrique <erick.henrique.rodrigues@usp.br>
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/dac/m62332.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/dac/m62332.c b/drivers/iio/dac/m62332.c
index 3497513854d7..56cd0081afde 100644
--- a/drivers/iio/dac/m62332.c
+++ b/drivers/iio/dac/m62332.c
@@ -8,13 +8,13 @@
  *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
  */
 
+#include <linux/err.h>
+#include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/i2c.h>
-#include <linux/err.h>
 
-#include <linux/iio/iio.h>
 #include <linux/iio/driver.h>
+#include <linux/iio/iio.h>
 
 #include <linux/regulator/consumer.h>
 
-- 
2.51.0


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

* [PATCH v5 2/3] iio: dac: m62332: Clean up header includes
  2026-06-28  3:48 [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 1/3] iio: dac: m62332: Sort header includes alphabetically Erick Henrique
@ 2026-06-28  3:48 ` Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
  2 siblings, 0 replies; 5+ messages in thread
From: Erick Henrique @ 2026-06-28  3:48 UTC (permalink / raw)
  To: jic23
  Cc: andriy.shevchenko, andy, dlechner, nuno.sa, joshua.crofts1,
	linux-iio, Erick Henrique

Follow the IWYU principle: include specific headers for the symbols
used in this file and drop the unused slab.h. Add array_size.h, bits.h,
mutex.h, pm.h and types.h for symbols that were previously pulled in
only indirectly, and add mod_devicetable.h for the device ID table.
This prepares the driver for the guard(mutex) conversion that follows.

Signed-off-by: Erick Henrique <erick.henrique.rodrigues@usp.br>
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/dac/m62332.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/dac/m62332.c b/drivers/iio/dac/m62332.c
index 56cd0081afde..ee8fd3a71315 100644
--- a/drivers/iio/dac/m62332.c
+++ b/drivers/iio/dac/m62332.c
@@ -8,10 +8,16 @@
  *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
  */
 
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/device.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
-#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/types.h>
 
 #include <linux/iio/driver.h>
 #include <linux/iio/iio.h>
-- 
2.51.0


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

* [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking
  2026-06-28  3:48 [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 1/3] iio: dac: m62332: Sort header includes alphabetically Erick Henrique
  2026-06-28  3:48 ` [PATCH v5 2/3] iio: dac: m62332: Clean up header includes Erick Henrique
@ 2026-06-28  3:48 ` Erick Henrique
  2026-06-28 11:45   ` Joshua Crofts
  2 siblings, 1 reply; 5+ messages in thread
From: Erick Henrique @ 2026-06-28  3:48 UTC (permalink / raw)
  To: jic23
  Cc: andriy.shevchenko, andy, dlechner, nuno.sa, joshua.crofts1,
	linux-iio, Erick Henrique

Replace mutex_lock()/mutex_unlock() calls with guard(mutex)() to
simplify locking and make cleanup automatic when the lock goes out
of scope. Also simplify the i2c_master_send() error handling by
using sequential early returns instead of a combined condition.

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

diff --git a/drivers/iio/dac/m62332.c b/drivers/iio/dac/m62332.c
index ee8fd3a71315..3cde38ff5f65 100644
--- a/drivers/iio/dac/m62332.c
+++ b/drivers/iio/dac/m62332.c
@@ -10,6 +10,7 @@
 
 #include <linux/array_size.h>
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
@@ -47,33 +48,26 @@ 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;
+	if (res != ARRAY_SIZE(outbuf))
+		return -EIO;
 
 	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] 5+ messages in thread

* Re: [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking
  2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
@ 2026-06-28 11:45   ` Joshua Crofts
  0 siblings, 0 replies; 5+ messages in thread
From: Joshua Crofts @ 2026-06-28 11:45 UTC (permalink / raw)
  To: Erick Henrique
  Cc: jic23, andriy.shevchenko, andy, dlechner, nuno.sa, linux-iio

On Sun, 28 Jun 2026 00:48:11 -0300
Erick Henrique <erick.henrique.rodrigues@usp.br> wrote:

> Replace mutex_lock()/mutex_unlock() calls with guard(mutex)() to
> simplify locking and make cleanup automatic when the lock goes out
> of scope. Also simplify the i2c_master_send() error handling by
> using sequential early returns instead of a combined condition.
> 
> Signed-off-by: Erick Henrique <erick.henrique.rodrigues@usp.br>
> ---

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD

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

end of thread, other threads:[~2026-06-28 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-28  3:48 [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Erick Henrique
2026-06-28  3:48 ` [PATCH v5 1/3] iio: dac: m62332: Sort header includes alphabetically Erick Henrique
2026-06-28  3:48 ` [PATCH v5 2/3] iio: dac: m62332: Clean up header includes Erick Henrique
2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
2026-06-28 11:45   ` Joshua Crofts

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