From: Russell King <rmk+ker...@arm.linux.org.uk>

There are a couple of issues with etnaviv_add_components():
1. it releases each child node as it parses, which is unnecessary
   Fix this by using the for_each_available_child_of_node() helper
   rather than open-coding this.
2. it fails to check the return value from component_master_add_child().
   In this case, we must drop the child reference before breaking out
   of the loop.

Signed-off-by: Russell King <rmk+kernel at arm.linux.org.uk>
---
 drivers/staging/etnaviv/etnaviv_drv.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/etnaviv/etnaviv_drv.c 
b/drivers/staging/etnaviv/etnaviv_drv.c
index 39586b45200d..da7035ce07a2 100644
--- a/drivers/staging/etnaviv/etnaviv_drv.c
+++ b/drivers/staging/etnaviv/etnaviv_drv.c
@@ -527,19 +527,20 @@ static int etnaviv_compare(struct device *dev, void *data)

 static int etnaviv_add_components(struct device *master, struct master *m)
 {
-       struct device_node *np  = master->of_node;
        struct device_node *child_np;
+       int ret = 0;

-       child_np = of_get_next_available_child(np, NULL);
-
-       while (child_np) {
+       for_each_available_child_of_node(master->of_node, child_np) {
                DRM_INFO("add child %s\n", child_np->name);
-               component_master_add_child(m, etnaviv_compare, child_np);
-               of_node_put(child_np);
-               child_np = of_get_next_available_child(np, child_np);
+
+               ret = component_master_add_child(m, etnaviv_compare, child_np);
+               if (ret) {
+                       of_node_put(child_np);
+                       break;
+               }
        }

-       return 0;
+       return ret;
 }

 static int etnaviv_bind(struct device *dev)
-- 
2.1.4

Reply via email to