Skip to contentSkip to conversation

of/address: Don't loop forever in of_find_matching_node_by_address().

PATCH In review David Daney 2 participants 2 messages Aug 19, 2015 – Aug 24, 2015 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/address: Don't loop forever in of_find_matching_node_by_address().

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

If the internal call to of_address_to_resource() fails, we end up looping forever in of_find_matching_node_by_address(). This can be caused by a defective device tree, or calling with an incorrect matches argument.

Fix by calling of_find_matching_node() unconditionally at the end of the loop.

---
 drivers/of/address.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/address.c +3 -3
index 8bfda6a..384574c 100644
@@ -845,10 +845,10 @@ struct device_node *of_find_matching_node_by_address(struct device_node *from,
 	struct resource res;
 
 	while (dn) {
-		if (of_address_to_resource(dn, 0, &res))
-			continue;
-		if (res.start == base_address)
+		if (!of_address_to_resource(dn, 0, &res) &&
+		    res.start == base_address)
 			return dn;
+
 		dn = of_find_matching_node(dn, matches);
 	}
 
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 11 lines · David Daney

From: David Daney <[email protected]>

If the internal call to of_address_to_resource() fails, we end up looping forever in of_find_matching_node_by_address(). This can be caused by a defective device tree, or calling with an incorrect matches argument.

Fix by calling of_find_matching_node() unconditionally at the end of the loop.

Applied and tagged for stable. Thanks.

Rob

Quoted 25 lines
---
 drivers/of/address.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/address.c +3 -4
index 8bfda6a..384574c 100644
@@ -845,10 +845,10 @@ struct device_node *of_find_matching_node_by_address(struct device_node *from,
        struct resource res;
 
        while (dn) {
-               if (of_address_to_resource(dn, 0, &res))
-                       continue;
-               if (res.start == base_address)
+               if (!of_address_to_resource(dn, 0, &res) &&
+                   res.start == base_address)
                        return dn;
+
                dn = of_find_matching_node(dn, matches);
        }
 
--

1.9.1