Skip to content

Commit 5b2c2f5

Browse files
committed
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>
1 parent 7c528e4 commit 5b2c2f5

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

‎drivers/of/dynamic.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,6 @@ void __of_detach_node(struct device_node *np)
272272

273273
/**
274274
* 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.
278275
*/
279276
int of_detach_node(struct device_node *np)
280277
{

‎drivers/of/kobj.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np)
133133
}
134134
if (!name)
135135
return -ENOMEM;
136+
137+
of_node_get(np);
138+
136139
rc = kobject_add(&np->kobj, parent, "%s", name);
137140
kfree(name);
138141
if (rc)
@@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
159162
kobject_del(&np->kobj);
160163
}
161164

162-
/* finally remove the kobj_init ref */
163165
of_node_put(np);
164166
}

0 commit comments

Comments
 (0)