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
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ 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] 10+ 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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ 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] 10+ 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-29 16:39   ` Andy Shevchenko
  2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
  2026-06-29 17:23 ` [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Andy Shevchenko
  3 siblings, 1 reply; 10+ 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] 10+ 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
  2026-06-29 17:23 ` [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Andy Shevchenko
  3 siblings, 1 reply; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread

* Re: [PATCH v5 2/3] iio: dac: m62332: Clean up header includes
  2026-06-28  3:48 ` [PATCH v5 2/3] iio: dac: m62332: Clean up header includes Erick Henrique
@ 2026-06-29 16:39   ` Andy Shevchenko
  2026-06-29 17:07     ` Joshua Crofts
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-06-29 16:39 UTC (permalink / raw)
  To: Erick Henrique; +Cc: jic23, andy, dlechner, nuno.sa, joshua.crofts1, linux-iio

On Sun, Jun 28, 2026 at 12:48:10AM -0300, Erick Henrique wrote:
> 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.

...

> +#include <linux/array_size.h>
> +#include <linux/bits.h>

> +#include <linux/device.h>

And this is for..?

I can assume one wants to convert the driver to use dev_get_drvdata() perhaps?

>  #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>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v5 2/3] iio: dac: m62332: Clean up header includes
  2026-06-29 16:39   ` Andy Shevchenko
@ 2026-06-29 17:07     ` Joshua Crofts
  2026-06-29 17:15       ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Joshua Crofts @ 2026-06-29 17:07 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Erick Henrique, jic23, andy, dlechner, nuno.sa, linux-iio

On Mon, 29 Jun 2026 19:39:05 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sun, Jun 28, 2026 at 12:48:10AM -0300, Erick Henrique wrote:
> > 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.  
> 
> ...
> 
> > +#include <linux/array_size.h>
> > +#include <linux/bits.h>  
> 
> > +#include <linux/device.h>  
> 
> And this is for..?
> 
> I can assume one wants to convert the driver to use dev_get_drvdata() perhaps?

I also initially thought it's a case of an opaque struct device * pointer,
but the driver already uses dev_get_platdata().

-- 
Kind regards

CJD

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

* Re: [PATCH v5 2/3] iio: dac: m62332: Clean up header includes
  2026-06-29 17:07     ` Joshua Crofts
@ 2026-06-29 17:15       ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-06-29 17:15 UTC (permalink / raw)
  To: Joshua Crofts; +Cc: Erick Henrique, jic23, andy, dlechner, nuno.sa, linux-iio

On Mon, Jun 29, 2026 at 07:07:06PM +0200, Joshua Crofts wrote:
> On Mon, 29 Jun 2026 19:39:05 +0300
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Sun, Jun 28, 2026 at 12:48:10AM -0300, Erick Henrique wrote:

...

> > > +#include <linux/array_size.h>
> > > +#include <linux/bits.h>  
> > 
> > > +#include <linux/device.h>  
> > 
> > And this is for..?
> > 
> > I can assume one wants to convert the driver to use dev_get_drvdata() perhaps?
> 
> I also initially thought it's a case of an opaque struct device * pointer,
> but the driver already uses dev_get_platdata().

Ah, that explains...

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex)
  2026-06-28  3:48 [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Erick Henrique
                   ` (2 preceding siblings ...)
  2026-06-28  3:48 ` [PATCH v5 3/3] iio: dac: m62332: Use guard(mutex) for locking Erick Henrique
@ 2026-06-29 17:23 ` Andy Shevchenko
  2026-07-01  0:07   ` Jonathan Cameron
  3 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-06-29 17:23 UTC (permalink / raw)
  To: Erick Henrique; +Cc: jic23, andy, dlechner, nuno.sa, joshua.crofts1, linux-iio

On Sun, Jun 28, 2026 at 12:48:08AM -0300, Erick Henrique wrote:
> This series cleans up the m62332 header includes and converts its locking
> to guard(mutex).

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex)
  2026-06-29 17:23 ` [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Andy Shevchenko
@ 2026-07-01  0:07   ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2026-07-01  0:07 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Erick Henrique, andy, dlechner, nuno.sa, joshua.crofts1,
	linux-iio

On Mon, 29 Jun 2026 20:23:24 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sun, Jun 28, 2026 at 12:48:08AM -0300, Erick Henrique wrote:
> > This series cleans up the m62332 header includes and converts its locking
> > to guard(mutex).  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 

This series is fine but your fix needs to go upstream first.
https://patchwork.kernel.org/project/linux-iio/patch/20260630021309.36636-2-erick.henrique.rodrigues@usp.br/

Then this will need a rebase for at least patch 3.

Thanks,

Jonathan

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

end of thread, other threads:[~2026-07-01  0:07 UTC | newest]

Thread overview: 10+ 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-29 16:39   ` Andy Shevchenko
2026-06-29 17:07     ` Joshua Crofts
2026-06-29 17:15       ` Andy Shevchenko
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
2026-06-29 17:23 ` [PATCH v5 0/3] iio: dac: m62332: header cleanup and guard(mutex) Andy Shevchenko
2026-07-01  0:07   ` Jonathan Cameron

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