]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.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)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837664
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 <atull@kernel.org>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/of/dynamic.c
drivers/of/kobj.c

index d2731794e1af09870598e705c0c8ec26c7497f0b..86c7e7230c78f5e1c260d3028a8170bbd2afa954 100644 (file)
@@ -271,9 +271,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 250fc7bb550fb429fe9b398c92eca730776dedaf..51f1579d15d389ffa4a2eb0f03e1c76f2ca41836 100644 (file)
@@ -132,6 +132,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)
@@ -158,7 +161,6 @@ void __of_detach_node_sysfs(struct device_node *np)
                kobject_del(&np->kobj);
        }
 
-       /* finally remove the kobj_init ref */
        of_node_put(np);
 }