Skip to contentSkip to conversation

of: Check 'of_node_reused' flag on of_match_device()

PATCH Applied Rob Herring 1 participant 2 messages Jan 18, 2022 – Jan 20, 2022 Device tree

lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

PATCH 1/1 of: Check 'of_node_reused' flag on of_match_device()

Commit 0f153a1b8193 ("usb: chipidea: Set the DT node on the child device") caused the child device to match on the parent driver instead of the child's driver since the child's DT node pointer matched. The worst case result is a loop of the parent driver probing another instance and creating yet another child device eventually exhausting the stack. If the child driver happens to match first, then everything works fine.

A device sharing the DT node should never do DT based driver matching, so let's simply check of_node_reused in of_match_device() to prevent that.

Fixes 0f153a1b8193 ("usb: chipidea: Set the DT node on the child device")
Cc Frank Rowand <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Peter Chen <[email protected]>
---
 drivers/of/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/device.c +1 -1
index b0800c260f64..874f031442dc 100644
@@ -28,7 +28,7 @@
 const struct of_device_id *of_match_device(const struct of_device_id *matches,
 					   const struct device *dev)
 {
-	if ((!matches) || (!dev->of_node))
+	if (!matches || !dev->of_node || dev->of_node_reused)
 		return NULL;
 	return of_match_node(matches, dev->of_node);
 }
Signature · 1 line
2.32.0
author maintainer Applied
#1 lore raw
Quoted 22 lines · Rob Herring

Commit 0f153a1b8193 ("usb: chipidea: Set the DT node on the child device") caused the child device to match on the parent driver instead of the child's driver since the child's DT node pointer matched. The worst case result is a loop of the parent driver probing another instance and creating yet another child device eventually exhausting the stack. If the child driver happens to match first, then everything works fine.

A device sharing the DT node should never do DT based driver matching, so let's simply check of_node_reused in of_match_device() to prevent that.

Fixes 0f153a1b8193 ("usb: chipidea: Set the DT node on the child device")
Cc Frank Rowand <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Peter Chen <[email protected]>
Quoted 4 lines
---
 drivers/of/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks!