Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: overlay: add missing of_node_get() in __of_attach_node_sysfs

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>

+3 -4
-3
drivers/of/dynamic.c
··· 272 272 273 273 /** 274 274 * of_detach_node() - "Unplug" a node from the device tree. 275 - * 276 - * The caller must hold a reference to the node. The memory associated with 277 - * the node is not freed until its refcount goes to zero. 278 275 */ 279 276 int of_detach_node(struct device_node *np) 280 277 {
+3 -1
drivers/of/kobj.c
··· 133 133 } 134 134 if (!name) 135 135 return -ENOMEM; 136 + 137 + of_node_get(np); 138 + 136 139 rc = kobject_add(&np->kobj, parent, "%s", name); 137 140 kfree(name); 138 141 if (rc) ··· 162 159 kobject_del(&np->kobj); 163 160 } 164 161 165 - /* finally remove the kobj_init ref */ 166 162 of_node_put(np); 167 163 }