public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] gpio: pca9570: Ad-hoc cleanups
@ 2026-01-13 10:08 Andy Shevchenko
  2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-13 10:08 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

Looking at this driver for something else I took the opportunity
to clean it up. Hence this mini-series.

Andy Shevchenko (3):
  gpio: pca9570: Use devm_mutex_init() for mutex initialization
  gpio: pca9570: Don't use "proxy" headers
  gpio: pca9570: use lock guards

 drivers/gpio/gpio-pca9570.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

-- 
2.50.1


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

* [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
  2026-01-13 10:08 [PATCH v1 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
@ 2026-01-13 10:08 ` Andy Shevchenko
  2026-01-13 10:16   ` Linus Walleij
  2026-01-13 11:01   ` Bartosz Golaszewski
  2026-01-13 10:08 ` [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers Andy Shevchenko
  2026-01-13 10:08 ` [PATCH v1 3/3] gpio: pca9570: use lock guards Andy Shevchenko
  2 siblings, 2 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-13 10:08 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
cleanup during probe failure and driver removal.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca9570.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c
index c5a1287079a0..eae35135c71e 100644
--- a/drivers/gpio/gpio-pca9570.c
+++ b/drivers/gpio/gpio-pca9570.c
@@ -115,7 +115,9 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
 
 static int pca9570_probe(struct i2c_client *client)
 {
+	struct device *dev = &client->dev;
 	struct pca9570 *gpio;
+	int ret;
 
 	gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL);
 	if (!gpio)
@@ -132,7 +134,9 @@ static int pca9570_probe(struct i2c_client *client)
 	gpio->chip.ngpio = gpio->chip_data->ngpio;
 	gpio->chip.can_sleep = true;
 
-	mutex_init(&gpio->lock);
+	ret = devm_mutex_init(dev, &gpio->lock);
+	if (ret)
+		return ret;
 
 	/* Read the current output level */
 	pca9570_read(gpio, &gpio->out);
-- 
2.50.1


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

* [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers
  2026-01-13 10:08 [PATCH v1 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
  2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
@ 2026-01-13 10:08 ` Andy Shevchenko
  2026-01-13 10:17   ` Linus Walleij
  2026-01-13 10:08 ` [PATCH v1 3/3] gpio: pca9570: use lock guards Andy Shevchenko
  2 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-13 10:08 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

Update header inclusions to follow IWYU (Include What You Use)
principle.

Note that kernel.h is discouraged to be included as it's written
at the top of that file.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca9570.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c
index eae35135c71e..a41837f1201b 100644
--- a/drivers/gpio/gpio-pca9570.c
+++ b/drivers/gpio/gpio-pca9570.c
@@ -9,11 +9,15 @@
  *	Andrew F. Davis <afd@ti.com>
  */
 
+#include <linux/bits.h>
+#include <linux/device/devres.h>
+#include <linux/errno.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/property.h>
+#include <linux/types.h>
 
 #define SLG7XL45106_GPO_REG	0xDB
 
-- 
2.50.1


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

* [PATCH v1 3/3] gpio: pca9570: use lock guards
  2026-01-13 10:08 [PATCH v1 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
  2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
  2026-01-13 10:08 ` [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers Andy Shevchenko
@ 2026-01-13 10:08 ` Andy Shevchenko
  2026-01-13 10:17   ` Linus Walleij
  2 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-13 10:08 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

Shrink the code by a couple lines and improve lock management by using
lock guards from cleanup.h.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca9570.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c
index a41837f1201b..4a368803fb03 100644
--- a/drivers/gpio/gpio-pca9570.c
+++ b/drivers/gpio/gpio-pca9570.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/device/devres.h>
 #include <linux/errno.h>
 #include <linux/gpio/driver.h>
@@ -98,7 +99,7 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
 	u8 buffer;
 	int ret;
 
-	mutex_lock(&gpio->lock);
+	guard(mutex)(&gpio->lock);
 
 	buffer = gpio->out;
 	if (value)
@@ -108,13 +109,11 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
 
 	ret = pca9570_write(gpio, buffer);
 	if (ret)
-		goto out;
+		return ret;
 
 	gpio->out = buffer;
 
-out:
-	mutex_unlock(&gpio->lock);
-	return ret;
+	return 0;
 }
 
 static int pca9570_probe(struct i2c_client *client)
-- 
2.50.1


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

* Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
  2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
@ 2026-01-13 10:16   ` Linus Walleij
  2026-01-13 11:01   ` Bartosz Golaszewski
  1 sibling, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2026-01-13 10:16 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> cleanup during probe failure and driver removal.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

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

* Re: [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers
  2026-01-13 10:08 ` [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers Andy Shevchenko
@ 2026-01-13 10:17   ` Linus Walleij
  0 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2026-01-13 10:17 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Update header inclusions to follow IWYU (Include What You Use)
> principle.
>
> Note that kernel.h is discouraged to be included as it's written
> at the top of that file.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

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

* Re: [PATCH v1 3/3] gpio: pca9570: use lock guards
  2026-01-13 10:08 ` [PATCH v1 3/3] gpio: pca9570: use lock guards Andy Shevchenko
@ 2026-01-13 10:17   ` Linus Walleij
  0 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2026-01-13 10:17 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Shrink the code by a couple lines and improve lock management by using
> lock guards from cleanup.h.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

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

* Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
  2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
  2026-01-13 10:16   ` Linus Walleij
@ 2026-01-13 11:01   ` Bartosz Golaszewski
  2026-01-13 11:12     ` Andy Shevchenko
  1 sibling, 1 reply; 9+ messages in thread
From: Bartosz Golaszewski @ 2026-01-13 11:01 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel, Linus Walleij

On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> cleanup during probe failure and driver removal.
>

Well, I can almost hear Johan Hovold yelling at you that this is not
about mutex cleanup but merely a useless debugging feature.

Though personally, I'm fine with it. Just reword the commit message
because there's no actual cleanup happening other than freeing the
memory allocated for the devres entry. :)

Bartosz

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

* Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
  2026-01-13 11:01   ` Bartosz Golaszewski
@ 2026-01-13 11:12     ` Andy Shevchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-13 11:12 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Linus Walleij

On Tue, Jan 13, 2026 at 12:01:40PM +0100, Bartosz Golaszewski wrote:
> On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> > cleanup during probe failure and driver removal.
> 
> Well, I can almost hear Johan Hovold yelling at you that this is not
> about mutex cleanup but merely a useless debugging feature.
> 
> Though personally, I'm fine with it. Just reword the commit message
> because there's no actual cleanup happening other than freeing the
> memory allocated for the devres entry. :)

v2 is sent, thanks for review!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-01-13 11:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-13 10:08 [PATCH v1 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
2026-01-13 10:08 ` [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
2026-01-13 10:16   ` Linus Walleij
2026-01-13 11:01   ` Bartosz Golaszewski
2026-01-13 11:12     ` Andy Shevchenko
2026-01-13 10:08 ` [PATCH v1 2/3] gpio: pca9570: Don't use "proxy" headers Andy Shevchenko
2026-01-13 10:17   ` Linus Walleij
2026-01-13 10:08 ` [PATCH v1 3/3] gpio: pca9570: use lock guards Andy Shevchenko
2026-01-13 10:17   ` Linus Walleij

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