Skip to contentSkip to conversation

gpio: of: Allow overriding the device node

PATCH In review Thierry Reding 4 participants 5 messages Jul 5, 2016 – Jul 6, 2016

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

PATCH 1/1 gpio: of: Allow overriding the device node

From: Thierry Reding <[email protected]>

When registering a GPIO chip, drivers can override the device tree node associated with the chip by setting the chip's ->of_node field. If set, this field is supposed to take precedence over the ->parent->of_node field, but the code doesn't actually do that.

Commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data") exposes this because it now no longer matches on the GPIO chip's ->of_node field, but the GPIO device's ->of_node field that is set using the procedure described above.

---
 drivers/gpio/gpiolib.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +5 -4
index 47a3cc0e437b..eae7664b2723 100644
@@ -1047,13 +1047,14 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
 	if (chip->parent) {
 		gdev->dev.parent = chip->parent;
 		gdev->dev.of_node = chip->parent->of_node;
-	} else {
+	}
+
 #ifdef CONFIG_OF_GPIO
 	/* If the gpiochip has an assigned OF node this takes precedence */
-		if (chip->of_node)
-			gdev->dev.of_node = chip->of_node;
+	if (chip->of_node)
+		gdev->dev.of_node = chip->of_node;
 #endif
-	}
+
 	gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL);
 	if (gdev->id < 0) {
 		status = gdev->id;
Signature · 1 line
2.8.3
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When registering a GPIO chip, drivers can override the device tree node associated with the chip by setting the chip's ->of_node field. If set, this field is supposed to take precedence over the ->parent->of_node field, but the code doesn't actually do that.

Commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data") exposes this because it now no longer matches on the GPIO chip's ->of_node field, but the GPIO device's ->of_node field that is set using the procedure described above.

#2 lore raw
In reply to Thierry Reding
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When registering a GPIO chip, drivers can override the device tree node associated with the chip by setting the chip's ->of_node field. If set, this field is supposed to take precedence over the ->parent->of_node field, but the code doesn't actually do that.

Quoted 6 lines

Commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data") exposes this because it now no longer matches on the GPIO chip's ->of_node field, but the GPIO device's ->of_node field that is set using the procedure described above.

Thanks for catching this, patch applied with Alexandre's ACK.

Masahiro: does this look all right to you?

Yours,
Linus Walleij

Reviewed-by
#3 lore raw

Hi.

2016-07-06 0:25 GMT+09:00 Linus Walleij <[email protected]>:

Quoted 14 lines · Thierry Reding
Quoted 13 lines

From: Thierry Reding <[email protected]>

When registering a GPIO chip, drivers can override the device tree node associated with the chip by setting the chip's ->of_node field. If set, this field is supposed to take precedence over the ->parent->of_node field, but the code doesn't actually do that.

Commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data") exposes this because it now no longer matches on the GPIO chip's ->of_node field, but the GPIO device's ->of_node field that is set using the procedure described above.

Quoted 5 lines
Quoted 1 line

Thanks for catching this, patch applied with Alexandre's ACK.

Masahiro: does this look all right to you?

Yes.
Now, the code matches to the comment. Nice!

Question:

When we reference the node of gpiochip,
we should use
chip->gpiodev->dev->of_node

instead of
chip->of_node

because we can make chip->of_node optional as long as chip->parent is set in the probe method.

Correct?

Signature · 2 lines
Best Regards
Masahiro Yamada
#4 lore raw
Quoted 6 lines · Masahiro Yamada

Question:

When we reference the node of gpiochip,
we should use
chip->gpiodev->dev->of_node

Quoted 7 lines

instead of
chip->of_node

because we can make chip->of_node optional as long as chip->parent is set in the probe method.

Correct?

Yes, if you see any bug with respect to this, just fix them.

Overall my appraisal of the situation is that it's a mess. chip->of_node should not exist, we need to investigate all cases where this is actually used by drivers and kill them all off, they should all be using the parent to pass the device containing the right of node so we can get rid of this:

#ifdef CONFIG_OF_GPIO
        /* If the gpiochip has an assigned OF node this takes precedence */
        if (chip->of_node)
                gdev->dev.of_node = chip->of_node;

#endif

I don't know why this extra OF node is there in the first place and in which circumstances it may be used, maybe Grant knows.

I understand so much as that it would be a situation where you have a GPIO device node but it does not have a corresponding device of any type, but I fail to see what circumstance would make that happen.

Yours,
Linus Walleij