Skip to contentSkip to conversation

gpio: shared: fix some corner cases

PATCH Applied Bartosz Golaszewski 2 participants 5 messages Nov 26, 2025 – Nov 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: shared: fix some corner cases

Here are fixes for two more bugs reported in linux-next.

---
Bartosz Golaszewski (2):
gpio: shared: ignore special __symbols__ node when traversing device tree
gpio: shared: ignore GPIO hogs when traversing the device tree

 drivers/gpio/gpiolib-shared.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

---
base-commit: 3fc91e5912eb3761d7b19e6ee8eb92749e856316
change-id: 20251126-gpio-shared-fixes-080ab392483f

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#1 lore raw

PATCH 1/2 gpio: shared: ignore special __symbols__ node when traversing device tree

From: Bartosz Golaszewski <[email protected]>

The __symbols__ node is a special, internal node and its properties must not be considered when scanning the device-tree for shared GPIOs.

Fixes a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
---
 drivers/gpio/gpiolib-shared.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpio/gpiolib-shared.c +16 -0
index 3803b5c938f9933dab01c6d777c349ed3b42ce9b..62f32489a8a6f70c567ed93645f1e36a81612def 100644
@@ -73,6 +73,19 @@ gpio_shared_find_entry(struct fwnode_handle *controller_node,
 	return NULL;
 }
 
+/* Handle all special nodes that we should ignore. */
+static bool gpio_shared_of_node_ignore(struct device_node *node)
+{
+	/*
+	 * __symbols__ is a special, internal node and should not be considered
+	 * when scanning for shared GPIOs.
+	 */
+	if (of_node_name_eq(node, "__symbols__"))
+		return true;
+
+	return false;
+}
+
 static int gpio_shared_of_traverse(struct device_node *curr)
 {
 	struct gpio_shared_entry *entry;
@@ -84,6 +97,9 @@ static int gpio_shared_of_traverse(struct device_node *curr)
 	const char *suffix;
 	int ret, count, i;
 
+	if (gpio_shared_of_node_ignore(curr))
+		return 0;
+
 	for_each_property_of_node(curr, prop) {
 		/*
 		 * The standard name for a GPIO property is "foo-gpios"
Signature · 1 line
2.51.0
maintainer Tested-by Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] gpio: shared: ignore special __symbols__ node when traversing device tree

Quoted 39 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The __symbols__ node is a special, internal node and its properties must not be considered when scanning the device-tree for shared GPIOs.

Fixes a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
---
  drivers/gpio/gpiolib-shared.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
drivers/gpio/gpiolib-shared.c +13 -0
index 3803b5c938f9933dab01c6d777c349ed3b42ce9b..62f32489a8a6f70c567ed93645f1e36a81612def 100644
@@ -73,6 +73,19 @@ gpio_shared_find_entry(struct fwnode_handle *controller_node,
  	return NULL;
  }
 
+/* Handle all special nodes that we should ignore. */
+static bool gpio_shared_of_node_ignore(struct device_node *node)
+{
+	/*
+	 * __symbols__ is a special, internal node and should not be considered
+	 * when scanning for shared GPIOs.
+	 */
+	if (of_node_name_eq(node, "__symbols__"))
+		return true;
+
+	return false;
+}
+
  static int gpio_shared_of_traverse(struct device_node *curr)
  {
  	struct gpio_shared_entry *entry;

drivers/gpio/gpiolib-shared.c static int gpio_shared_of_traverse(struct device_node *curr) · line 105

Quoted 9 lines
drivers/gpio/gpiolib-shared.c +3 -0
@@ -84,6 +97,9 @@ static int gpio_shared_of_traverse(struct device_node *curr)
  	const char *suffix;
  	int ret, count, i;
 
+	if (gpio_shared_of_node_ignore(curr))
+		return 0;
+
  	for_each_property_of_node(curr, prop) {
  		/*
  		 * The standard name for a GPIO property is "foo-gpios"

Fixes it for me!

Thanks
Jon

Signature · 1 line
nvpublic
#3 lore raw

PATCH 2/2 gpio: shared: ignore GPIO hogs when traversing the device tree

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

GPIO hogs have a "gpios" property but it's not a phandle to a remote node - it references the parent GPIO controller. We must not try to parse it as a phandle.

Fixes a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
---
 drivers/gpio/gpiolib-shared.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpio/gpiolib-shared.c +7 -0
index 62f32489a8a6f70c567ed93645f1e36a81612def..7e049f2153a3fcc51803dd185fe5db60daea789f 100644
@@ -83,6 +83,13 @@ static bool gpio_shared_of_node_ignore(struct device_node *node)
 	if (of_node_name_eq(node, "__symbols__"))
 		return true;
 
+	/*
+	 * GPIO hogs have a "gpios" property which is not a phandle and can't
+	 * possibly refer to a shared GPIO.
+	 */
+	if (of_property_present(node, "gpio-hog"))
+		return true;
+
 	return false;
 }
 
Signature · 1 line
2.51.0
author Applied
#4 lore raw
In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 3 lines · Bartosz Golaszewski

Here are fixes for two more bugs reported in linux-next.

Applied, thanks!

[1/2] gpio: shared: ignore special __symbols__ node when traversing device tree

      https://git.kernel.org/brgl/linux/c/cfab6dc0700c3b9120dab726fc184c3b4500cc5b
[2/2] gpio: shared: ignore GPIO hogs when traversing the device tree
      https://git.kernel.org/brgl/linux/c/114e594e6cb791ce7c839ccfbe153ecfa3e7abce

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>