From: Frank Rowand Date: Fri, 5 Oct 2018 03:26:05 +0000 (-0700) Subject: of: overlay: add missing of_node_get() in __of_attach_node_sysfs X-Git-Tag: v4.20.7~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5933abd0743489f89d165cdfd372467d9c100c8f;p=thirdparty%2Fkernel%2Fstable.git of: overlay: add missing of_node_get() in __of_attach_node_sysfs commit 5b2c2f5a0ea3a43e0dee78059e34c7cb54136dcc 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: Alan Tull Acked-by: Michael Ellerman (powerpc) Signed-off-by: Frank Rowand Cc: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 0ea0b8f2e25bd..45c0b1f4cb69f 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -275,9 +275,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) { diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 7a0a18980b98b..c72eef9880417 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -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); }