Skip to contentSkip to conversation

gpio: swnode: compare the "undefined" swnode by its address, not name

PATCH Applied Bartosz Golaszewski 3 participants 5 messages Dec 15, 2025 – Dec 28, 2025 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: swnode: compare the "undefined" swnode by its address, not name

We know the address of the underlying remote software node referenced by the GPIO property (if it is a software node). We don't need to compare its name, we can compare its address which is more precise anyway.

---
 drivers/gpio/gpiolib-swnode.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib-swnode.c +4 -7
index b44f35d684590..54bad9e88fe5c 100644
@@ -18,19 +18,18 @@
 
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
+#include <linux/gpio/property.h>
 
 #include "gpiolib.h"
 #include "gpiolib-swnode.h"
 
-#define GPIOLIB_SWNODE_UNDEFINED_NAME "swnode-gpio-undefined"
-
 static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
 {
 	const struct software_node *gdev_node;
 	struct gpio_device *gdev;
 
 	gdev_node = to_software_node(fwnode);
-	if (!gdev_node || !gdev_node->name)
+	if (!gdev_node)
 		goto fwnode_lookup;
 
 	/*
@@ -38,7 +37,7 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
 	 * 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))
+	    gdev_node == &swnode_gpio_undefined)
 		return ERR_PTR(-ENOENT);
 
 fwnode_lookup:
@@ -139,9 +138,7 @@ int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
  * A special node that identifies undefined GPIOs, this is primarily used as
  * a key for internal chip selects in SPI bindings.
  */
-const struct software_node swnode_gpio_undefined = {
-	.name = GPIOLIB_SWNODE_UNDEFINED_NAME,
-};
+const struct software_node swnode_gpio_undefined = { };
 EXPORT_SYMBOL_NS_GPL(swnode_gpio_undefined, "GPIO_SWNODE");
 
 static int __init swnode_gpio_init(void)
Signature · 1 line
2.51.0
author Applied
#2 lore raw
In reply to Bartosz Golaszewski
Quoted 5 lines · Bartosz Golaszewski

We know the address of the underlying remote software node referenced by the GPIO property (if it is a software node). We don't need to compare its name, we can compare its address which is more precise anyway.

Applied, thanks!

[1/1] gpio: swnode: compare the "undefined" swnode by its address, not name

      commit: 6774a66d0e103d0e3e4c0f37dbd61946ec83edf0

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#3 lore raw
Quoted 10 lines · Bartosz Golaszewski
Quoted 3 lines · Bartosz Golaszewski

We know the address of the underlying remote software node referenced by the GPIO property (if it is a software node). We don't need to compare its name, we can compare its address which is more precise anyway.

Applied, thanks!

[1/1] gpio: swnode: compare the "undefined" swnode by its address, not name

      commit: 6774a66d0e103d0e3e4c0f37dbd61946ec83edf0

Okay, but still consider returning the name. The idea of comparing with the address I agree with.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Bartosz Golaszewski
Quoted 3 lines · Bartosz Golaszewski

We know the address of the underlying remote software node referenced by the GPIO property (if it is a software node). We don't need to compare its name, we can compare its address which is more precise anyway.

...

drivers/gpio/gpiolib-swnode.c int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) · line 141

Quoted 4 lines
drivers/gpio/gpiolib-swnode.c +1 -3
-const struct software_node swnode_gpio_undefined = {
-	.name = GPIOLIB_SWNODE_UNDEFINED_NAME,
-};
+const struct software_node swnode_gpio_undefined = { };

This will remove the name from sysfs, which may be informative.

Signature · 2 lines
With Best Regards,
Andy Shevchenko