]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
of: overlay: add missing of_node_get() in __of_attach_node_sysfs
authorFrank Rowand <frank.rowand@sony.com>
Fri, 5 Oct 2018 03:26:05 +0000 (20:26 -0700)
committerFrank Rowand <frank.rowand@sony.com>
Fri, 9 Nov 2018 06:10:53 +0000 (22:10 -0800)
There is a matching of_node_put() in __of_detach_node_sysfs()

Remove misleading comment from function header comment for
of_detach_node().

This patch may result in memory leaks from code that directly calls
the dynamic node add and delete functions directly instead of
using changesets.

This commit should result in powerpc systems that dynamically
allocate a node, then later deallocate the node to have a
memory leak when the node is deallocated.

The next commit will fix the leak.

Tested-by: Alan Tull <atull@kernel.org>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
drivers/of/dynamic.c
drivers/of/kobj.c

index 12c3f9a15e94c7d2663565c13dfceda5c52926e0..146681540487aadc3161f658e3bf89bccbe1cb20 100644 (file)
@@ -272,9 +272,6 @@ void __of_detach_node(struct device_node *np)
 
 /**
  * of_detach_node() - "Unplug" a node from the device tree.
- *
- * The caller must hold a reference to the node.  The memory associated with
- * the node is not freed until its refcount goes to zero.
  */
 int of_detach_node(struct device_node *np)
 {
index 7a0a18980b98b7688ef5637e4fffc4176f493206..c72eef98804175c9d21fc9043c6582aec04bde13 100644 (file)
@@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np)
        }
        if (!name)
                return -ENOMEM;
+
+       of_node_get(np);
+
        rc = kobject_add(&np->kobj, parent, "%s", name);
        kfree(name);
        if (rc)
@@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
                kobject_del(&np->kobj);
        }
 
-       /* finally remove the kobj_init ref */
        of_node_put(np);
 }