]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
of: resolver: Add missing of_node_get and of_node_put
authorAmitoj Kaur Chawla <amitoj1606@gmail.com>
Wed, 3 Feb 2016 18:09:01 +0000 (23:39 +0530)
committerRob Herring <robh@kernel.org>
Sat, 13 Feb 2016 19:35:32 +0000 (13:35 -0600)
In __of_find_node_by_full_name, add an of_node_get when detecting the
desired element, to ensure that it ends up with a reference count that is
one greater than on entering the function.

Also in __of_find_node_by_full_name, add an of_node_put on breaking
out of the for_each_child_of_node loop, to ensure that the reference
count of the returned value is not double incremented. This change
was made using Coccinelle.

The semantic patch used for this is as follows:

// <smpl>
@@
expression e;
local idexpression n;
@@

 for_each_child_of_node(..., n) {
   ... when != of_node_put(n)
       when != e = n
(
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }
// </smpl

Finally, add an of_node_put in for_each_child_of_node in the function
__of_adjust_phandle_ref after the value returned by
__of_find_node_by_full_name is no longer useful.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/resolver.c

index 640eb4cb46e392926103ba798b2cda0a1b32be99..d313d492f2786de8811cdc6396a10882e37c3d00 100644 (file)
@@ -36,12 +36,14 @@ static struct device_node *__of_find_node_by_full_name(struct device_node *node,
 
        /* check */
        if (of_node_cmp(node->full_name, full_name) == 0)
-               return node;
+               return of_node_get(node);
 
        for_each_child_of_node(node, child) {
                found = __of_find_node_by_full_name(child, full_name);
-               if (found != NULL)
+               if (found != NULL) {
+                       of_node_put(child);
                        return found;
+               }
        }
 
        return NULL;
@@ -174,6 +176,7 @@ static int __of_adjust_phandle_ref(struct device_node *node,
                        if (of_prop_cmp(sprop->name, propstr) == 0)
                                break;
                }
+               of_node_put(refnode);
 
                if (!sprop) {
                        pr_err("%s: Could not find property '%s'\n",