public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups
@ 2026-01-13 11:10 Andy Shevchenko
  2026-01-13 11:10 ` [PATCH v2 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-01-13 11:10 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.

Changelog v2:
- rephrased commit message in patch 1 (Bart)
- collected tags (Linus)

v1: 20260113100913.136777-1-andriy.shevchenko@linux.intel.com

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] 5+ messages in thread

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

Use devm_mutex_init() since it brings some benefits when
CONFIG_DEBUG_MUTEXES is enabled.

Reviewed-by: Linus Walleij <linusw@kernel.org>
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] 5+ messages in thread

* [PATCH v2 2/3] gpio: pca9570: Don't use "proxy" headers
  2026-01-13 11:10 [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
  2026-01-13 11:10 ` [PATCH v2 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
@ 2026-01-13 11:10 ` Andy Shevchenko
  2026-01-13 11:10 ` [PATCH v2 3/3] gpio: pca9570: use lock guards Andy Shevchenko
  2026-01-13 14:17 ` [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-01-13 11:10 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.

Reviewed-by: Linus Walleij <linusw@kernel.org>
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] 5+ messages in thread

* [PATCH v2 3/3] gpio: pca9570: use lock guards
  2026-01-13 11:10 [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
  2026-01-13 11:10 ` [PATCH v2 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization Andy Shevchenko
  2026-01-13 11:10 ` [PATCH v2 2/3] gpio: pca9570: Don't use "proxy" headers Andy Shevchenko
@ 2026-01-13 11:10 ` Andy Shevchenko
  2026-01-13 14:17 ` [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-01-13 11:10 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.

Reviewed-by: Linus Walleij <linusw@kernel.org>
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] 5+ messages in thread

* Re: [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups
  2026-01-13 11:10 [PATCH v2 0/3] gpio: pca9570: Ad-hoc cleanups Andy Shevchenko
                   ` (2 preceding siblings ...)
  2026-01-13 11:10 ` [PATCH v2 3/3] gpio: pca9570: use lock guards Andy Shevchenko
@ 2026-01-13 14:17 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-01-13 14:17 UTC (permalink / raw)
  To: linux-gpio, linux-kernel, Andy Shevchenko
  Cc: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski


On Tue, 13 Jan 2026 12:10:51 +0100, Andy Shevchenko wrote:
> Looking at this driver for something else I took the opportunity
> to clean it up. Hence this mini-series.
> 
> Changelog v2:
> - rephrased commit message in patch 1 (Bart)
> - collected tags (Linus)
> 
> [...]

Applied, thanks!

[1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
      commit: e05ef046ebb1ca879d885593130fa822ff664ca1
[2/3] gpio: pca9570: Don't use "proxy" headers
      commit: 053578d329e58cca98f084439e14cc2895c82b9c
[3/3] gpio: pca9570: use lock guards
      commit: 4aa573002ba6884d392dbfce24c3ce057f2dbb6a

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

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

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

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