Skip to contentSkip to conversation

gpiolib: use of_node_name if line-name is missing

PATCH Superseded Frank Wunderlich 2 participants 5 messages Sep 17 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: use of_node_name if line-name is missing

From: Frank Wunderlich <[email protected]>

Until v7.0, GPIO hogs inherited the DT node name when no line-name property was specified. This was implemented as a fallback in of_parse_own_gpio().

Commit d1d564ec4992 ("gpio: move hogs into GPIO core") moved hog parsing into the GPIO core and removed this fallback.

Consequently, GPIO hogs without a line-name property are now displayed with a ? in /sys/kernel/debug/gpio. Restore the old fallback.

Fixes d1d564ec4992 ("gpio: move hogs into GPIO core")
---
 drivers/gpio/gpiolib.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpiolib.c +3 -0
index ef8ccaf17c9c..acf41cfbcf10 100644
@@ -1013,6 +1013,9 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
+	if (!name && is_of_node(fwnode))
+		name = to_of_node(fwnode)->name;
+
 	for (unsigned int i = 0; i < num_hogs; i++) {
 		if (is_of_node(fwnode)) {
 			/*
Signature · 1 line
2.53.0
#1 lore raw
Quoted 9 lines · Frank Wunderlich

Until v7.0, GPIO hogs inherited the DT node name when no line-name property was specified. This was implemented as a fallback in of_parse_own_gpio().

Commit d1d564ec4992 ("gpio: move hogs into GPIO core") moved hog parsing into the GPIO core and removed this fallback.

Consequently, GPIO hogs without a line-name property are now displayed with a ? in /sys/kernel/debug/gpio. Restore the old fallback.

...

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1017

Quoted 6 lines

int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)

drivers/gpio/gpiolib.c +2 -0
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
+	if (!name && is_of_node(fwnode))
+		name = to_of_node(fwnode)->name;

Can we move it inside the loop? Yes, I understand that it will be unnecessarily called more times than required, but gpiod_hog() is called anyway in the loop, so I don't think it will be a big deal. With that it will allow to group OF-specific code in one location.

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1020

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
 	for (unsigned int i = 0; i < num_hogs; i++) {
 		if (is_of_node(fwnode)) {

...somewhere inside this conditional...

Quoted 1 line

/*

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

Am 2026-09-17 15:00, schrieb Andy Shevchenko:

Quoted 26 lines · Frank Wunderlich
Quoted 10 lines

Until v7.0, GPIO hogs inherited the DT node name when no line-name property was specified. This was implemented as a fallback in of_parse_own_gpio().

Commit d1d564ec4992 ("gpio: move hogs into GPIO core") moved hog parsing into the GPIO core and removed this fallback.

Consequently, GPIO hogs without a line-name property are now displayed with a ? in /sys/kernel/debug/gpio. Restore the old fallback.

...

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1017

Quoted 6 lines

int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)

drivers/gpio/gpiolib.c +2 -0
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
+	if (!name && is_of_node(fwnode))
+		name = to_of_node(fwnode)->name;

Can we move it inside the loop? Yes, I understand that it will be unnecessarily called more times than required, but gpiod_hog() is called anyway in the loop, so I don't think it will be a big deal. With that it will allow to group OF-specific code in one location.

Quoted 6 lines

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1020

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
 	for (unsigned int i = 0; i < num_hogs; i++) {
 		if (is_of_node(fwnode)) {

...somewhere inside this conditional...

Quoted 1 line

/*

I'm not sure what you want to achieve here (maybe only to have the is_of_node-condition once?, as the loop imho is only for enumerating multiple gpio (like "gpios = <3 0>, <4 0>;") inside one hog of_node. Here the node-name will never change (like the line-name above) and read-once is correct. But while looking at the code i also thought about these multi-gpio-hogs (label and output-X). Imho here something like the gpio-controllers "line-names" would make sense as well as something similar for the output (or just handling this with the GPIO_ACTIVE_HIGH/LOW param).

But if you think the part should be moved into the loop, that's no big deal.

regards Frank

#3 lore raw
Quoted 2 lines · Frank Wunderlich (linux)

Am 2026-09-17 15:00, schrieb Andy Shevchenko:

Quoted 1 line · Frank Wunderlich

...

Quoted 18 lines
Quoted 18 lines

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1017

Quoted 7 lines

int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)

drivers/gpio/gpiolib.c +2 -0
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
+	if (!name && is_of_node(fwnode))
+		name = to_of_node(fwnode)->name;

Can we move it inside the loop? Yes, I understand that it will be unnecessarily
called more times than required, but gpiod_hog() is called anyway in the loop,
so I don't think it will be a big deal. With that it will allow to group OF-specific code in one location.

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
 	for (unsigned int i = 0; i < num_hogs; i++) {
 		if (is_of_node(fwnode)) {
Quoted 7 lines
Quoted 3 lines

...somewhere inside this conditional...

Quoted 1 line

/*

I'm not sure what you want to achieve here (maybe only to have the is_of_node-condition once?, as the loop imho is only for enumerating multiple gpio (like "gpios = <3 0>, <4 0>;") inside one hog of_node.

The primary goal is stop spreading OF-specific code. If you have noticed the function was also rewritten (during the move) to be fwnode agnostic, but that was not feasible by 100%, the leftover is collected inside the mentioned loop. That's why I really prefer to keep all OF code there.

Quoted 8 lines

Here the node-name will never change (like the line-name above) and read-once is correct.
But while looking at the code i also thought about these multi-gpio-hogs (label and output-X). Imho here something like the gpio-controllers "line-names" would make sense as well as something similar for the output (or just handling this with the GPIO_ACTIVE_HIGH/LOW param).

But if you think the part should be moved into the loop, that's no big deal.

Yes, I think that way.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Frank Wunderlich (linux)

Am 2026-09-17 15:00, schrieb Andy Shevchenko:

Quoted 1 line · Frank Wunderlich

...

Quoted 38 lines
Quoted 18 lines
Quoted 18 lines

drivers/gpio/gpiolib.c int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) · line 1017

Quoted 7 lines

int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)

drivers/gpio/gpiolib.c +2 -0
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
+	if (!name && is_of_node(fwnode))
+		name = to_of_node(fwnode)->name;

Can we move it inside the loop? Yes, I understand that it will be unnecessarily
called more times than required, but gpiod_hog() is called anyway in the loop,
so I don't think it will be a big deal. With that it will allow to group OF-specific code in one location.

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
 	for (unsigned int i = 0; i < num_hogs; i++) {
 		if (is_of_node(fwnode)) {
Quoted 7 lines
Quoted 3 lines

...somewhere inside this conditional...

Quoted 1 line

/*

I'm not sure what you want to achieve here (maybe only to have the is_of_node-condition once?, as the loop imho is only for enumerating multiple gpio (like "gpios = <3 0>, <4 0>;") inside one hog of_node.

The primary goal is stop spreading OF-specific code. If you have noticed the function was also rewritten (during the move) to be fwnode agnostic, but that was not feasible by 100%, the leftover is collected inside the mentioned loop. That's why I really prefer to keep all OF code there.

Quoted 7 lines

Here the node-name will never change (like the line-name above) and read-once is correct.
But while looking at the code i also thought about these multi-gpio-hogs (label and output-X). Imho here something like the gpio-controllers "line-names" would make sense as well as something similar for the output (or just handling this with the GPIO_ACTIVE_HIGH/LOW param).

Quoted 3 lines
Quoted 1 line

But if you think the part should be moved into the loop, that's no big deal.

Yes, I think that way.

Btw, while doing that, also add a comment explaining why (like we have now for the OF flag translations).

Signature · 2 lines
With Best Regards,
Andy Shevchenko