Commit 9af27fab authored by Frank Rowand's avatar Frank Rowand Committed by Greg Kroah-Hartman

of: overlay: add missing of_node_get() in __of_attach_node_sysfs

commit 5b2c2f5a upstream.

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: default avatarAlan Tull <atull@kernel.org>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5006496f
...@@ -275,9 +275,6 @@ void __of_detach_node(struct device_node *np) ...@@ -275,9 +275,6 @@ void __of_detach_node(struct device_node *np)
/** /**
* of_detach_node() - "Unplug" a node from the device tree. * 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) int of_detach_node(struct device_node *np)
{ {
......
...@@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np) ...@@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np)
} }
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
of_node_get(np);
rc = kobject_add(&np->kobj, parent, "%s", name); rc = kobject_add(&np->kobj, parent, "%s", name);
kfree(name); kfree(name);
if (rc) if (rc)
...@@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np) ...@@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
kobject_del(&np->kobj); kobject_del(&np->kobj);
} }
/* finally remove the kobj_init ref */
of_node_put(np); of_node_put(np);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment