mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: use of_get_child_by_name() to find child node
@ 2020-04-14  9:06 Michael Tretter
  2020-04-14  9:13 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Tretter @ 2020-04-14  9:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Michael Tretter

After iterating the children of a node with for_each_child_of_node(),
the child node will never be NULL. If the node was not found,
overlay_child will always point to the first element in the list, which
might or might not be the node that was searched.

Use the of_get_child_by_name() helper function to find the child node
with the name, which does the right thing and returns NULL if the node
is not found.

Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/of/resolver.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 9107c1fbb68c..4f720cf860c2 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -160,9 +160,7 @@ static int adjust_local_phandle_references(struct device_node *local_fixups,
 	}
 
 	for_each_child_of_node(local_fixups, child) {
-		for_each_child_of_node(overlay, overlay_child)
-			if (!of_node_cmp(child->name, overlay_child->name))
-				break;
+		overlay_child = of_get_child_by_name(overlay, child->name);
 		if (!overlay_child)
 			return -EINVAL;
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] of: use of_get_child_by_name() to find child node
  2020-04-14  9:06 [PATCH] of: use of_get_child_by_name() to find child node Michael Tretter
@ 2020-04-14  9:13 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-04-14  9:13 UTC (permalink / raw)
  To: Michael Tretter; +Cc: barebox, Ahmad Fatoum

On Tue, Apr 14, 2020 at 11:06:10AM +0200, Michael Tretter wrote:
> After iterating the children of a node with for_each_child_of_node(),
> the child node will never be NULL. If the node was not found,
> overlay_child will always point to the first element in the list, which
> might or might not be the node that was searched.
> 
> Use the of_get_child_by_name() helper function to find the child node
> with the name, which does the right thing and returns NULL if the node
> is not found.
> 
> Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
>  drivers/of/resolver.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-14  9:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14  9:06 [PATCH] of: use of_get_child_by_name() to find child node Michael Tretter
2020-04-14  9:13 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox