[PATCH v4 05/10] gpio: swnode: allow referencing GPIO chips by firmware nodes

Bartosz Golaszewski posted 10 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v4 05/10] gpio: swnode: allow referencing GPIO chips by firmware nodes
Posted by Bartosz Golaszewski 3 months, 1 week ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

When doing a software node lookup, we require both the fwnode that
references a GPIO chip as well as the node associated with that chip to
be software nodes. However, we now allow referencing generic firmware
nodes from software nodes in driver core so we should allow the same in
GPIO core. Make the software node name check optional and dependent on
whether the referenced firmware node is a software node. If it's not,
just continue with the lookup.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib-swnode.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c
index e3806db1c0e077d76fcc71a50ca40bbf6872ca40..16af83fcc5aa886dd009dedc26b1ac23e5cbc4ea 100644
--- a/drivers/gpio/gpiolib-swnode.c
+++ b/drivers/gpio/gpiolib-swnode.c
@@ -30,16 +30,15 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
 	struct gpio_device *gdev;
 
 	gdev_node = to_software_node(fwnode);
-	if (!gdev_node || !gdev_node->name)
-		return ERR_PTR(-EINVAL);
-
-	/*
-	 * Check for a special node that identifies undefined GPIOs, this is
-	 * primarily used as a key for internal chip selects in SPI bindings.
-	 */
-	if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
-	    !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
-		return ERR_PTR(-ENOENT);
+	if (gdev_node && gdev_node->name) {
+		/*
+		 * Check for a special node that identifies undefined GPIOs, this is
+		 * primarily used as a key for internal chip selects in SPI bindings.
+		 */
+		if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
+		    !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
+			return ERR_PTR(-ENOENT);
+	}
 
 	gdev = gpio_device_find_by_fwnode(fwnode);
 	return gdev ?: ERR_PTR(-EPROBE_DEFER);

-- 
2.51.0
Re: [PATCH v4 05/10] gpio: swnode: allow referencing GPIO chips by firmware nodes
Posted by Andy Shevchenko 3 months, 1 week ago
On Mon, Nov 03, 2025 at 10:35:25AM +0100, Bartosz Golaszewski wrote:
> 
> When doing a software node lookup, we require both the fwnode that
> references a GPIO chip as well as the node associated with that chip to
> be software nodes. However, we now allow referencing generic firmware
> nodes from software nodes in driver core so we should allow the same in
> GPIO core. Make the software node name check optional and dependent on
> whether the referenced firmware node is a software node. If it's not,
> just continue with the lookup.

...

>  	gdev_node = to_software_node(fwnode);
> -	if (!gdev_node || !gdev_node->name)
> -		return ERR_PTR(-EINVAL);

The whole patch can be done in two lines (1 changed, 1 added):

		goto out_fwnode_lookup;

> -	/*
> -	 * Check for a special node that identifies undefined GPIOs, this is
> -	 * primarily used as a key for internal chip selects in SPI bindings.
> -	 */
> -	if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
> -	    !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
> -		return ERR_PTR(-ENOENT);
> +	if (gdev_node && gdev_node->name) {
> +		/*
> +		 * Check for a special node that identifies undefined GPIOs, this is
> +		 * primarily used as a key for internal chip selects in SPI bindings.
> +		 */
> +		if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
> +		    !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
> +			return ERR_PTR(-ENOENT);
> +	}

out_fwnode_lookup:

>  	gdev = gpio_device_find_by_fwnode(fwnode);
>  	return gdev ?: ERR_PTR(-EPROBE_DEFER);

-- 
With Best Regards,
Andy Shevchenko