mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/4] gpio: Unify the GPIO controller node check
@ 2026-08-24  7:42 Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 1/4] gpio: Split fwnode_is_gpiochip() helper Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  7:42 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, linux-gpio, linux-kernel,
	linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

There are handful of drivers perform the same check in different variations
over and over with a potential to make subtle mistakes. Unify the check by
providing a new helper and convert a few users as an example.

Andy Shevchenko (4):
  gpio: Split fwnode_is_gpiochip() helper
  gpio: shared: Replace open coded fwnode_is_gpiochip()
  pinctrl: ma35: Replace open coded fwnode_is_gpiochip()
  pinctrl: pistachio: Replace open coded fwnode_is_gpiochip()

 drivers/gpio/gpiolib-shared.c          | 6 ++----
 drivers/pinctrl/nuvoton/pinctrl-ma35.c | 4 ++--
 drivers/pinctrl/pinctrl-pistachio.c    | 2 +-
 include/linux/gpio/driver.h            | 7 ++++++-
 4 files changed, 11 insertions(+), 8 deletions(-)

-- 
2.50.1


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

* [PATCH v1 1/4] gpio: Split fwnode_is_gpiochip() helper
  2026-08-24  7:42 [PATCH v1 0/4] gpio: Unify the GPIO controller node check Andy Shevchenko
@ 2026-08-24  7:42 ` Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip() Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  7:42 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, linux-gpio, linux-kernel,
	linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

Many drivers repeat the same over and over. For clarity and robustness
split fwnode_is_gpiochip() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/gpio/driver.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 2ea21341adea..06d40fb77a73 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -879,9 +879,14 @@ static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc,
 }
 #endif /* CONFIG_GPIOLIB */
 
+static inline bool fwnode_is_gpiochip(struct fwnode_handle *fwnode)
+{
+	return fwnode_property_present(child, "gpio-controller");
+}
+
 #define for_each_gpiochip_node(dev, child)					\
 	device_for_each_child_node(dev, child)					\
-		for_each_if(fwnode_property_present(child, "gpio-controller"))
+		for_each_if(fwnode_is_gpiochip(child))
 
 static inline unsigned int gpiochip_node_count(struct device *dev)
 {
-- 
2.50.1


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

* [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip()
  2026-08-24  7:42 [PATCH v1 0/4] gpio: Unify the GPIO controller node check Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 1/4] gpio: Split fwnode_is_gpiochip() helper Andy Shevchenko
@ 2026-08-24  7:42 ` Andy Shevchenko
  2026-08-24  8:37   ` Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 3/4] pinctrl: ma35: " Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 4/4] pinctrl: pistachio: " Andy Shevchenko
  3 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  7:42 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, linux-gpio, linux-kernel,
	linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

Since GPIOLIB provides a helper, no need to open code it, hence
replace that piece by fwnode_is_gpiochip().

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

diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index 495bd3d0ddf0..be90926dffcc 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -203,9 +203,8 @@ static int gpio_shared_of_traverse(struct device_node *curr)
 			if (ret)
 				continue;
 
-			np = args.np;
-
-			if (!of_property_present(np, "gpio-controller"))
+			fwnode = of_fwnode_handle(args.np);
+			if (!fwnode_is_gpiochip(fwnode))
 				continue;
 
 			/*
@@ -222,7 +221,6 @@ static int gpio_shared_of_traverse(struct device_node *curr)
 			if (args.args_count != 2)
 				continue;
 
-			fwnode = of_fwnode_handle(args.np);
 			offset = args.args[0];
 
 			entry = gpio_shared_find_entry(fwnode, offset);
-- 
2.50.1


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

* [PATCH v1 3/4] pinctrl: ma35: Replace open coded fwnode_is_gpiochip()
  2026-08-24  7:42 [PATCH v1 0/4] gpio: Unify the GPIO controller node check Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 1/4] gpio: Split fwnode_is_gpiochip() helper Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip() Andy Shevchenko
@ 2026-08-24  7:42 ` Andy Shevchenko
  2026-08-24  7:42 ` [PATCH v1 4/4] pinctrl: pistachio: " Andy Shevchenko
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  7:42 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, linux-gpio, linux-kernel,
	linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

Since GPIOLIB provides a helper, no need to open code it, hence
replace that piece by fwnode_is_gpiochip().

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

diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index dafa85c105a1..922b727c4b6c 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -1075,7 +1075,7 @@ static int ma35_pinctrl_probe_dt(struct platform_device *pdev, struct ma35_pinct
 	int ret;
 
 	device_for_each_child_node(dev, child) {
-		if (fwnode_property_present(child, "gpio-controller"))
+		if (fwnode_is_gpiochip(child))
 			continue;
 
 		npctl->nfunctions++;
@@ -1096,7 +1096,7 @@ static int ma35_pinctrl_probe_dt(struct platform_device *pdev, struct ma35_pinct
 		return -ENOMEM;
 
 	device_for_each_child_node(dev, child) {
-		if (fwnode_property_present(child, "gpio-controller"))
+		if (fwnode_is_gpiochip(child))
 			continue;
 
 		ret = ma35_pinctrl_parse_functions(child, npctl, idx++);
-- 
2.50.1


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

* [PATCH v1 4/4] pinctrl: pistachio: Replace open coded fwnode_is_gpiochip()
  2026-08-24  7:42 [PATCH v1 0/4] gpio: Unify the GPIO controller node check Andy Shevchenko
                   ` (2 preceding siblings ...)
  2026-08-24  7:42 ` [PATCH v1 3/4] pinctrl: ma35: " Andy Shevchenko
@ 2026-08-24  7:42 ` Andy Shevchenko
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  7:42 UTC (permalink / raw)
  To: Bartosz Golaszewski, Andy Shevchenko, linux-gpio, linux-kernel,
	linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

Since GPIOLIB provides a helper, no need to open code it, hence
replace that piece by fwnode_is_gpiochip().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/pinctrl-pistachio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
index cc5cd2a538c5..32463733f7d7 100644
--- a/drivers/pinctrl/pinctrl-pistachio.c
+++ b/drivers/pinctrl/pinctrl-pistachio.c
@@ -1383,7 +1383,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
 			goto err;
 		}
 
-		if (!fwnode_property_present(child, "gpio-controller")) {
+		if (!fwnode_is_gpiochip(child)) {
 			fwnode_handle_put(child);
 			dev_err(pctl->dev,
 				"No gpio-controller property for bank %u\n", i);
-- 
2.50.1


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

* Re: [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip()
  2026-08-24  7:42 ` [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip() Andy Shevchenko
@ 2026-08-24  8:37   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  8:37 UTC (permalink / raw)
  To: Bartosz Golaszewski, linux-gpio, linux-kernel, linux-arm-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Jacky Huang, Shan-Chun Hung

On Mon, Aug 24, 2026 at 09:42:33AM +0200, Andy Shevchenko wrote:
> Since GPIOLIB provides a helper, no need to open code it, hence
> replace that piece by fwnode_is_gpiochip().

...

> -			np = args.np;

Ah, this one is important.
It seems that

                        struct device_node *np __free(device_node) = NULL;

needs to be replaced with

                        struct fwnode_handle *node __free(fwnode_handle) = NULL;

or something alike between the lines.

> -			if (!of_property_present(np, "gpio-controller"))
> +			fwnode = of_fwnode_handle(args.np);
> +			if (!fwnode_is_gpiochip(fwnode))
>  				continue;

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-08-24  8:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-24  7:42 [PATCH v1 0/4] gpio: Unify the GPIO controller node check Andy Shevchenko
2026-08-24  7:42 ` [PATCH v1 1/4] gpio: Split fwnode_is_gpiochip() helper Andy Shevchenko
2026-08-24  7:42 ` [PATCH v1 2/4] gpio: shared: Replace open coded fwnode_is_gpiochip() Andy Shevchenko
2026-08-24  8:37   ` Andy Shevchenko
2026-08-24  7:42 ` [PATCH v1 3/4] pinctrl: ma35: " Andy Shevchenko
2026-08-24  7:42 ` [PATCH v1 4/4] pinctrl: pistachio: " Andy Shevchenko

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

all inboxes | Powered by JetHome®