* [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-16 17:51 ` Frank Rowand
0 siblings, 0 replies; 8+ messages in thread
From: Frank Rowand @ 2016-06-16 17:51 UTC (permalink / raw)
To: Mathieu Malaterre, Rob Herring; +Cc: devicetree, linuxppc-dev, linux-kernel
From: Frank Rowand <frank.rowand@am.sony.com>
Fix a memory leak resulting from memory allocation in safe_name().
This patch fixes all call sites of safe_name().
Mathieu Malaterre reported the memory leak on boot:
On my PowerMac device-tree would generate a duplicate name:
[ 0.023043] device-tree: Duplicate name in PowerPC,G4@0, renamed to "l2-cache#1"
in this case a newly allocated name is generated by `safe_name`. However
in this case it is never deallocated.
The bug was found using kmemleak reported as:
unreferenced object 0xdf532e60 (size 32):
comm "swapper", pid 1, jiffies 4294892300 (age 1993.532s)
hex dump (first 32 bytes):
6c 32 2d 63 61 63 68 65 23 31 00 dd e4 dd 1e c2 l2-cache#1......
ec d4 ba ce 04 ec cc de 8e 85 e9 ca c4 ec cc 9e ................
backtrace:
[<c02d3350>] kvasprintf+0x64/0xc8
[<c02d3400>] kasprintf+0x4c/0x5c
[<c0453814>] safe_name.isra.1+0x80/0xc4
[<c04545d8>] __of_attach_node_sysfs+0x6c/0x11c
[<c075f21c>] of_core_init+0x8c/0xf8
[<c0729594>] kernel_init_freeable+0xd4/0x208
[<c00047e8>] kernel_init+0x24/0x11c
[<c00158ec>] ret_from_kernel_thread+0x5c/0x64
Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331
Signed-off-by: Frank Rowand <frank.rowand@am.sony.com>
Reported-by: mathieu.malaterre@gmail.com
---
changes from v1
Move the prototype of __of_sysfs_remove_bin_file() into of_private.h
changes from v2
Add the kfree that was in Mathieu's original patch
drivers/of/base.c | 30 +++++++++++++++++++++---------
drivers/of/dynamic.c | 2 +-
drivers/of/of_private.h | 3 +++
3 files changed, 25 insertions(+), 10 deletions(-)
Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -112,6 +112,7 @@ static ssize_t of_node_property_read(str
return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
}
+/* always return newly allocated name, caller must free after use */
static const char *safe_name(struct kobject *kobj, const char *orig_name)
{
const char *name = orig_name;
@@ -126,9 +127,12 @@ static const char *safe_name(struct kobj
name = kasprintf(GFP_KERNEL, "%s#%i", orig_name, ++i);
}
- if (name != orig_name)
+ if (name == orig_name) {
+ name = kstrdup(orig_name, GFP_KERNEL);
+ } else {
pr_warn("device-tree: Duplicate name in %s, renamed to \"%s\"\n",
kobject_name(kobj), name);
+ }
return name;
}
@@ -159,6 +163,7 @@ int __of_add_property_sysfs(struct devic
int __of_attach_node_sysfs(struct device_node *np)
{
const char *name;
+ struct kobject *parent;
struct property *pp;
int rc;
@@ -171,15 +176,16 @@ int __of_attach_node_sysfs(struct device
np->kobj.kset = of_kset;
if (!np->parent) {
/* Nodes without parents are new top level trees */
- rc = kobject_add(&np->kobj, NULL, "%s",
- safe_name(&of_kset->kobj, "base"));
+ name = safe_name(&of_kset->kobj, "base");
+ parent = NULL;
} else {
name = safe_name(&np->parent->kobj, kbasename(np->full_name));
- if (!name || !name[0])
- return -EINVAL;
-
- rc = kobject_add(&np->kobj, &np->parent->kobj, "%s", name);
+ parent = &np->parent->kobj;
}
+ if (!name)
+ return -ENOMEM;
+ rc = kobject_add(&np->kobj, parent, "%s", name);
+ kfree(name);
if (rc)
return rc;
@@ -1815,6 +1821,12 @@ int __of_remove_property(struct device_n
return 0;
}
+void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
+{
+ sysfs_remove_bin_file(&np->kobj, &prop->attr);
+ kfree(prop->attr.attr.name);
+}
+
void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
{
if (!IS_ENABLED(CONFIG_SYSFS))
@@ -1822,7 +1834,7 @@ void __of_remove_property_sysfs(struct d
/* at early boot, bail here and defer setup to of_init() */
if (of_kset && of_node_is_attached(np))
- sysfs_remove_bin_file(&np->kobj, &prop->attr);
+ __of_sysfs_remove_bin_file(np, prop);
}
/**
@@ -1895,7 +1907,7 @@ void __of_update_property_sysfs(struct d
return;
if (oldprop)
- sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
+ __of_sysfs_remove_bin_file(np, oldprop);
__of_add_property_sysfs(np, newprop);
}
Index: b/drivers/of/dynamic.c
===================================================================
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -55,7 +55,7 @@ void __of_detach_node_sysfs(struct devic
/* only remove properties if on sysfs */
if (of_node_is_attached(np)) {
for_each_property_of_node(np, pp)
- sysfs_remove_bin_file(&np->kobj, &pp->attr);
+ __of_sysfs_remove_bin_file(np, pp);
kobject_del(&np->kobj);
}
Index: b/drivers/of/of_private.h
===================================================================
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -83,6 +83,9 @@ extern int __of_attach_node_sysfs(struct
extern void __of_detach_node(struct device_node *np);
extern void __of_detach_node_sysfs(struct device_node *np);
+extern void __of_sysfs_remove_bin_file(struct device_node *np,
+ struct property *prop);
+
/* iterators for transactions, used for overlays */
/* forward iterator */
#define for_each_transaction_entry(_oft, _te) \
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-16 17:51 ` Frank Rowand
0 siblings, 0 replies; 8+ messages in thread
From: Frank Rowand @ 2016-06-16 17:51 UTC (permalink / raw)
To: Mathieu Malaterre, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linuxppc-dev,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Frank Rowand <frank.rowand-mEdOJwZ7QcZBDgjK7y7TUQ@public.gmane.org>
Fix a memory leak resulting from memory allocation in safe_name().
This patch fixes all call sites of safe_name().
Mathieu Malaterre reported the memory leak on boot:
On my PowerMac device-tree would generate a duplicate name:
[ 0.023043] device-tree: Duplicate name in PowerPC,G4@0, renamed to "l2-cache#1"
in this case a newly allocated name is generated by `safe_name`. However
in this case it is never deallocated.
The bug was found using kmemleak reported as:
unreferenced object 0xdf532e60 (size 32):
comm "swapper", pid 1, jiffies 4294892300 (age 1993.532s)
hex dump (first 32 bytes):
6c 32 2d 63 61 63 68 65 23 31 00 dd e4 dd 1e c2 l2-cache#1......
ec d4 ba ce 04 ec cc de 8e 85 e9 ca c4 ec cc 9e ................
backtrace:
[<c02d3350>] kvasprintf+0x64/0xc8
[<c02d3400>] kasprintf+0x4c/0x5c
[<c0453814>] safe_name.isra.1+0x80/0xc4
[<c04545d8>] __of_attach_node_sysfs+0x6c/0x11c
[<c075f21c>] of_core_init+0x8c/0xf8
[<c0729594>] kernel_init_freeable+0xd4/0x208
[<c00047e8>] kernel_init+0x24/0x11c
[<c00158ec>] ret_from_kernel_thread+0x5c/0x64
Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331
Signed-off-by: Frank Rowand <frank.rowand-mEdOJwZ7QcZBDgjK7y7TUQ@public.gmane.org>
Reported-by: mathieu.malaterre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
---
changes from v1
Move the prototype of __of_sysfs_remove_bin_file() into of_private.h
changes from v2
Add the kfree that was in Mathieu's original patch
drivers/of/base.c | 30 +++++++++++++++++++++---------
drivers/of/dynamic.c | 2 +-
drivers/of/of_private.h | 3 +++
3 files changed, 25 insertions(+), 10 deletions(-)
Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -112,6 +112,7 @@ static ssize_t of_node_property_read(str
return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
}
+/* always return newly allocated name, caller must free after use */
static const char *safe_name(struct kobject *kobj, const char *orig_name)
{
const char *name = orig_name;
@@ -126,9 +127,12 @@ static const char *safe_name(struct kobj
name = kasprintf(GFP_KERNEL, "%s#%i", orig_name, ++i);
}
- if (name != orig_name)
+ if (name == orig_name) {
+ name = kstrdup(orig_name, GFP_KERNEL);
+ } else {
pr_warn("device-tree: Duplicate name in %s, renamed to \"%s\"\n",
kobject_name(kobj), name);
+ }
return name;
}
@@ -159,6 +163,7 @@ int __of_add_property_sysfs(struct devic
int __of_attach_node_sysfs(struct device_node *np)
{
const char *name;
+ struct kobject *parent;
struct property *pp;
int rc;
@@ -171,15 +176,16 @@ int __of_attach_node_sysfs(struct device
np->kobj.kset = of_kset;
if (!np->parent) {
/* Nodes without parents are new top level trees */
- rc = kobject_add(&np->kobj, NULL, "%s",
- safe_name(&of_kset->kobj, "base"));
+ name = safe_name(&of_kset->kobj, "base");
+ parent = NULL;
} else {
name = safe_name(&np->parent->kobj, kbasename(np->full_name));
- if (!name || !name[0])
- return -EINVAL;
-
- rc = kobject_add(&np->kobj, &np->parent->kobj, "%s", name);
+ parent = &np->parent->kobj;
}
+ if (!name)
+ return -ENOMEM;
+ rc = kobject_add(&np->kobj, parent, "%s", name);
+ kfree(name);
if (rc)
return rc;
@@ -1815,6 +1821,12 @@ int __of_remove_property(struct device_n
return 0;
}
+void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
+{
+ sysfs_remove_bin_file(&np->kobj, &prop->attr);
+ kfree(prop->attr.attr.name);
+}
+
void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
{
if (!IS_ENABLED(CONFIG_SYSFS))
@@ -1822,7 +1834,7 @@ void __of_remove_property_sysfs(struct d
/* at early boot, bail here and defer setup to of_init() */
if (of_kset && of_node_is_attached(np))
- sysfs_remove_bin_file(&np->kobj, &prop->attr);
+ __of_sysfs_remove_bin_file(np, prop);
}
/**
@@ -1895,7 +1907,7 @@ void __of_update_property_sysfs(struct d
return;
if (oldprop)
- sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
+ __of_sysfs_remove_bin_file(np, oldprop);
__of_add_property_sysfs(np, newprop);
}
Index: b/drivers/of/dynamic.c
===================================================================
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -55,7 +55,7 @@ void __of_detach_node_sysfs(struct devic
/* only remove properties if on sysfs */
if (of_node_is_attached(np)) {
for_each_property_of_node(np, pp)
- sysfs_remove_bin_file(&np->kobj, &pp->attr);
+ __of_sysfs_remove_bin_file(np, pp);
kobject_del(&np->kobj);
}
Index: b/drivers/of/of_private.h
===================================================================
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -83,6 +83,9 @@ extern int __of_attach_node_sysfs(struct
extern void __of_detach_node(struct device_node *np);
extern void __of_detach_node_sysfs(struct device_node *np);
+extern void __of_sysfs_remove_bin_file(struct device_node *np,
+ struct property *prop);
+
/* iterators for transactions, used for overlays */
/* forward iterator */
#define for_each_transaction_entry(_oft, _te) \
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-17 7:51 ` Mathieu Malaterre
0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Malaterre @ 2016-06-17 7:51 UTC (permalink / raw)
To: Frank Rowand; +Cc: Rob Herring, devicetree, linuxppc-dev, linux-kernel
v3 tested here multiple times ! memleak is now gone.
Tested-by: Mathieu Malaterre <mathieu.malaterre@gmail.com>
Thanks
On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list@gmail.com> wrote:
> From: Frank Rowand <frank.rowand@am.sony.com>
>
> Fix a memory leak resulting from memory allocation in safe_name().
> This patch fixes all call sites of safe_name().
>
> Mathieu Malaterre reported the memory leak on boot:
>
> On my PowerMac device-tree would generate a duplicate name:
>
> [ 0.023043] device-tree: Duplicate name in PowerPC,G4@0, renamed to "l2-cache#1"
>
> in this case a newly allocated name is generated by `safe_name`. However
> in this case it is never deallocated.
>
> The bug was found using kmemleak reported as:
>
> unreferenced object 0xdf532e60 (size 32):
> comm "swapper", pid 1, jiffies 4294892300 (age 1993.532s)
> hex dump (first 32 bytes):
> 6c 32 2d 63 61 63 68 65 23 31 00 dd e4 dd 1e c2 l2-cache#1......
> ec d4 ba ce 04 ec cc de 8e 85 e9 ca c4 ec cc 9e ................
> backtrace:
> [<c02d3350>] kvasprintf+0x64/0xc8
> [<c02d3400>] kasprintf+0x4c/0x5c
> [<c0453814>] safe_name.isra.1+0x80/0xc4
> [<c04545d8>] __of_attach_node_sysfs+0x6c/0x11c
> [<c075f21c>] of_core_init+0x8c/0xf8
> [<c0729594>] kernel_init_freeable+0xd4/0x208
> [<c00047e8>] kernel_init+0x24/0x11c
> [<c00158ec>] ret_from_kernel_thread+0x5c/0x64
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331
>
> Signed-off-by: Frank Rowand <frank.rowand@am.sony.com>
> Reported-by: mathieu.malaterre@gmail.com
> ---
>
> changes from v1
> Move the prototype of __of_sysfs_remove_bin_file() into of_private.h
>
> changes from v2
> Add the kfree that was in Mathieu's original patch
>
> drivers/of/base.c | 30 +++++++++++++++++++++---------
> drivers/of/dynamic.c | 2 +-
> drivers/of/of_private.h | 3 +++
> 3 files changed, 25 insertions(+), 10 deletions(-)
>
> Index: b/drivers/of/base.c
> ===================================================================
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -112,6 +112,7 @@ static ssize_t of_node_property_read(str
> return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
> }
>
> +/* always return newly allocated name, caller must free after use */
> static const char *safe_name(struct kobject *kobj, const char *orig_name)
> {
> const char *name = orig_name;
> @@ -126,9 +127,12 @@ static const char *safe_name(struct kobj
> name = kasprintf(GFP_KERNEL, "%s#%i", orig_name, ++i);
> }
>
> - if (name != orig_name)
> + if (name == orig_name) {
> + name = kstrdup(orig_name, GFP_KERNEL);
> + } else {
> pr_warn("device-tree: Duplicate name in %s, renamed to \"%s\"\n",
> kobject_name(kobj), name);
> + }
> return name;
> }
>
> @@ -159,6 +163,7 @@ int __of_add_property_sysfs(struct devic
> int __of_attach_node_sysfs(struct device_node *np)
> {
> const char *name;
> + struct kobject *parent;
> struct property *pp;
> int rc;
>
> @@ -171,15 +176,16 @@ int __of_attach_node_sysfs(struct device
> np->kobj.kset = of_kset;
> if (!np->parent) {
> /* Nodes without parents are new top level trees */
> - rc = kobject_add(&np->kobj, NULL, "%s",
> - safe_name(&of_kset->kobj, "base"));
> + name = safe_name(&of_kset->kobj, "base");
> + parent = NULL;
> } else {
> name = safe_name(&np->parent->kobj, kbasename(np->full_name));
> - if (!name || !name[0])
> - return -EINVAL;
> -
> - rc = kobject_add(&np->kobj, &np->parent->kobj, "%s", name);
> + parent = &np->parent->kobj;
> }
> + if (!name)
> + return -ENOMEM;
> + rc = kobject_add(&np->kobj, parent, "%s", name);
> + kfree(name);
> if (rc)
> return rc;
>
> @@ -1815,6 +1821,12 @@ int __of_remove_property(struct device_n
> return 0;
> }
>
> +void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
> +{
> + sysfs_remove_bin_file(&np->kobj, &prop->attr);
> + kfree(prop->attr.attr.name);
> +}
> +
> void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
> {
> if (!IS_ENABLED(CONFIG_SYSFS))
> @@ -1822,7 +1834,7 @@ void __of_remove_property_sysfs(struct d
>
> /* at early boot, bail here and defer setup to of_init() */
> if (of_kset && of_node_is_attached(np))
> - sysfs_remove_bin_file(&np->kobj, &prop->attr);
> + __of_sysfs_remove_bin_file(np, prop);
> }
>
> /**
> @@ -1895,7 +1907,7 @@ void __of_update_property_sysfs(struct d
> return;
>
> if (oldprop)
> - sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
> + __of_sysfs_remove_bin_file(np, oldprop);
> __of_add_property_sysfs(np, newprop);
> }
>
> Index: b/drivers/of/dynamic.c
> ===================================================================
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -55,7 +55,7 @@ void __of_detach_node_sysfs(struct devic
> /* only remove properties if on sysfs */
> if (of_node_is_attached(np)) {
> for_each_property_of_node(np, pp)
> - sysfs_remove_bin_file(&np->kobj, &pp->attr);
> + __of_sysfs_remove_bin_file(np, pp);
> kobject_del(&np->kobj);
> }
>
> Index: b/drivers/of/of_private.h
> ===================================================================
> --- a/drivers/of/of_private.h
> +++ b/drivers/of/of_private.h
> @@ -83,6 +83,9 @@ extern int __of_attach_node_sysfs(struct
> extern void __of_detach_node(struct device_node *np);
> extern void __of_detach_node_sysfs(struct device_node *np);
>
> +extern void __of_sysfs_remove_bin_file(struct device_node *np,
> + struct property *prop);
> +
> /* iterators for transactions, used for overlays */
> /* forward iterator */
> #define for_each_transaction_entry(_oft, _te) \
--
Mathieu
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-17 7:51 ` Mathieu Malaterre
0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Malaterre @ 2016-06-17 7:51 UTC (permalink / raw)
To: Frank Rowand
Cc: Rob Herring, devicetree-u79uwXL29TY76Z2rM5mHXA, linuxppc-dev,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
v3 tested here multiple times ! memleak is now gone.
Tested-by: Mathieu Malaterre <mathieu.malaterre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Thanks
On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> From: Frank Rowand <frank.rowand-mEdOJwZ7QcZBDgjK7y7TUQ@public.gmane.org>
>
> Fix a memory leak resulting from memory allocation in safe_name().
> This patch fixes all call sites of safe_name().
>
> Mathieu Malaterre reported the memory leak on boot:
>
> On my PowerMac device-tree would generate a duplicate name:
>
> [ 0.023043] device-tree: Duplicate name in PowerPC,G4@0, renamed to "l2-cache#1"
>
> in this case a newly allocated name is generated by `safe_name`. However
> in this case it is never deallocated.
>
> The bug was found using kmemleak reported as:
>
> unreferenced object 0xdf532e60 (size 32):
> comm "swapper", pid 1, jiffies 4294892300 (age 1993.532s)
> hex dump (first 32 bytes):
> 6c 32 2d 63 61 63 68 65 23 31 00 dd e4 dd 1e c2 l2-cache#1......
> ec d4 ba ce 04 ec cc de 8e 85 e9 ca c4 ec cc 9e ................
> backtrace:
> [<c02d3350>] kvasprintf+0x64/0xc8
> [<c02d3400>] kasprintf+0x4c/0x5c
> [<c0453814>] safe_name.isra.1+0x80/0xc4
> [<c04545d8>] __of_attach_node_sysfs+0x6c/0x11c
> [<c075f21c>] of_core_init+0x8c/0xf8
> [<c0729594>] kernel_init_freeable+0xd4/0x208
> [<c00047e8>] kernel_init+0x24/0x11c
> [<c00158ec>] ret_from_kernel_thread+0x5c/0x64
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331
>
> Signed-off-by: Frank Rowand <frank.rowand-mEdOJwZ7QcZBDgjK7y7TUQ@public.gmane.org>
> Reported-by: mathieu.malaterre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> ---
>
> changes from v1
> Move the prototype of __of_sysfs_remove_bin_file() into of_private.h
>
> changes from v2
> Add the kfree that was in Mathieu's original patch
>
> drivers/of/base.c | 30 +++++++++++++++++++++---------
> drivers/of/dynamic.c | 2 +-
> drivers/of/of_private.h | 3 +++
> 3 files changed, 25 insertions(+), 10 deletions(-)
>
> Index: b/drivers/of/base.c
> ===================================================================
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -112,6 +112,7 @@ static ssize_t of_node_property_read(str
> return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
> }
>
> +/* always return newly allocated name, caller must free after use */
> static const char *safe_name(struct kobject *kobj, const char *orig_name)
> {
> const char *name = orig_name;
> @@ -126,9 +127,12 @@ static const char *safe_name(struct kobj
> name = kasprintf(GFP_KERNEL, "%s#%i", orig_name, ++i);
> }
>
> - if (name != orig_name)
> + if (name == orig_name) {
> + name = kstrdup(orig_name, GFP_KERNEL);
> + } else {
> pr_warn("device-tree: Duplicate name in %s, renamed to \"%s\"\n",
> kobject_name(kobj), name);
> + }
> return name;
> }
>
> @@ -159,6 +163,7 @@ int __of_add_property_sysfs(struct devic
> int __of_attach_node_sysfs(struct device_node *np)
> {
> const char *name;
> + struct kobject *parent;
> struct property *pp;
> int rc;
>
> @@ -171,15 +176,16 @@ int __of_attach_node_sysfs(struct device
> np->kobj.kset = of_kset;
> if (!np->parent) {
> /* Nodes without parents are new top level trees */
> - rc = kobject_add(&np->kobj, NULL, "%s",
> - safe_name(&of_kset->kobj, "base"));
> + name = safe_name(&of_kset->kobj, "base");
> + parent = NULL;
> } else {
> name = safe_name(&np->parent->kobj, kbasename(np->full_name));
> - if (!name || !name[0])
> - return -EINVAL;
> -
> - rc = kobject_add(&np->kobj, &np->parent->kobj, "%s", name);
> + parent = &np->parent->kobj;
> }
> + if (!name)
> + return -ENOMEM;
> + rc = kobject_add(&np->kobj, parent, "%s", name);
> + kfree(name);
> if (rc)
> return rc;
>
> @@ -1815,6 +1821,12 @@ int __of_remove_property(struct device_n
> return 0;
> }
>
> +void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
> +{
> + sysfs_remove_bin_file(&np->kobj, &prop->attr);
> + kfree(prop->attr.attr.name);
> +}
> +
> void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
> {
> if (!IS_ENABLED(CONFIG_SYSFS))
> @@ -1822,7 +1834,7 @@ void __of_remove_property_sysfs(struct d
>
> /* at early boot, bail here and defer setup to of_init() */
> if (of_kset && of_node_is_attached(np))
> - sysfs_remove_bin_file(&np->kobj, &prop->attr);
> + __of_sysfs_remove_bin_file(np, prop);
> }
>
> /**
> @@ -1895,7 +1907,7 @@ void __of_update_property_sysfs(struct d
> return;
>
> if (oldprop)
> - sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
> + __of_sysfs_remove_bin_file(np, oldprop);
> __of_add_property_sysfs(np, newprop);
> }
>
> Index: b/drivers/of/dynamic.c
> ===================================================================
> --- a/drivers/of/dynamic.c
> +++ b/drivers/of/dynamic.c
> @@ -55,7 +55,7 @@ void __of_detach_node_sysfs(struct devic
> /* only remove properties if on sysfs */
> if (of_node_is_attached(np)) {
> for_each_property_of_node(np, pp)
> - sysfs_remove_bin_file(&np->kobj, &pp->attr);
> + __of_sysfs_remove_bin_file(np, pp);
> kobject_del(&np->kobj);
> }
>
> Index: b/drivers/of/of_private.h
> ===================================================================
> --- a/drivers/of/of_private.h
> +++ b/drivers/of/of_private.h
> @@ -83,6 +83,9 @@ extern int __of_attach_node_sysfs(struct
> extern void __of_detach_node(struct device_node *np);
> extern void __of_detach_node_sysfs(struct device_node *np);
>
> +extern void __of_sysfs_remove_bin_file(struct device_node *np,
> + struct property *prop);
> +
> /* iterators for transactions, used for overlays */
> /* forward iterator */
> #define for_each_transaction_entry(_oft, _te) \
--
Mathieu
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-24 20:38 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2016-06-24 20:38 UTC (permalink / raw)
To: Mathieu Malaterre; +Cc: Frank Rowand, devicetree, linuxppc-dev, linux-kernel
On Fri, Jun 17, 2016 at 2:51 AM, Mathieu Malaterre
<mathieu.malaterre@gmail.com> wrote:
> v3 tested here multiple times ! memleak is now gone.
>
> Tested-by: Mathieu Malaterre <mathieu.malaterre@gmail.com>
>
> Thanks
>
> On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list@gmail.com> wrote:
>> From: Frank Rowand <frank.rowand@am.sony.com>
>>
>> Fix a memory leak resulting from memory allocation in safe_name().
>> This patch fixes all call sites of safe_name().
Applied, thanks.
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
@ 2016-06-24 20:38 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2016-06-24 20:38 UTC (permalink / raw)
To: Mathieu Malaterre
Cc: Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA, linuxppc-dev,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Fri, Jun 17, 2016 at 2:51 AM, Mathieu Malaterre
<mathieu.malaterre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> v3 tested here multiple times ! memleak is now gone.
>
> Tested-by: Mathieu Malaterre <mathieu.malaterre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> Thanks
>
> On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> From: Frank Rowand <frank.rowand-mEdOJwZ7QcZBDgjK7y7TUQ@public.gmane.org>
>>
>> Fix a memory leak resulting from memory allocation in safe_name().
>> This patch fixes all call sites of safe_name().
Applied, thanks.
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
2016-06-24 20:38 ` Rob Herring
(?)
@ 2016-07-20 6:03 ` Mathieu Malaterre
2016-07-22 19:58 ` Rob Herring
-1 siblings, 1 reply; 8+ messages in thread
From: Mathieu Malaterre @ 2016-07-20 6:03 UTC (permalink / raw)
To: Rob Herring; +Cc: Frank Rowand, devicetree, linuxppc-dev, linux-kernel
On Fri, Jun 24, 2016 at 10:38 PM, Rob Herring <robh+dt@kernel.org> wrote:
> On Fri, Jun 17, 2016 at 2:51 AM, Mathieu Malaterre
> <mathieu.malaterre@gmail.com> wrote:
>> v3 tested here multiple times ! memleak is now gone.
>>
>> Tested-by: Mathieu Malaterre <mathieu.malaterre@gmail.com>
>>
>> Thanks
>>
>> On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list@gmail.com> wrote:
>>> From: Frank Rowand <frank.rowand@am.sony.com>
>>>
>>> Fix a memory leak resulting from memory allocation in safe_name().
>>> This patch fixes all call sites of safe_name().
>
> Applied, thanks.
>
> Rob
Could this patch be considered for stable ?
Thx
--
Mathieu
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] of: fix memory leak related to safe_name()
2016-07-20 6:03 ` Mathieu Malaterre
@ 2016-07-22 19:58 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2016-07-22 19:58 UTC (permalink / raw)
To: Mathieu Malaterre; +Cc: Frank Rowand, devicetree, linuxppc-dev, linux-kernel
On Wed, Jul 20, 2016 at 1:03 AM, Mathieu Malaterre
<mathieu.malaterre@gmail.com> wrote:
> On Fri, Jun 24, 2016 at 10:38 PM, Rob Herring <robh+dt@kernel.org> wrote:
>> On Fri, Jun 17, 2016 at 2:51 AM, Mathieu Malaterre
>> <mathieu.malaterre@gmail.com> wrote:
>>> v3 tested here multiple times ! memleak is now gone.
>>>
>>> Tested-by: Mathieu Malaterre <mathieu.malaterre@gmail.com>
>>>
>>> Thanks
>>>
>>> On Thu, Jun 16, 2016 at 7:51 PM, Frank Rowand <frowand.list@gmail.com> wrote:
>>>> From: Frank Rowand <frank.rowand@am.sony.com>
>>>>
>>>> Fix a memory leak resulting from memory allocation in safe_name().
>>>> This patch fixes all call sites of safe_name().
>>
>> Applied, thanks.
>>
>> Rob
>
> Could this patch be considered for stable ?
Yes, I tagged it for stable. I didn't send it for 4.7, so it won't go
in until after 4.8-rc1 though.
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-07-22 19:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 17:51 [PATCH v3] of: fix memory leak related to safe_name() Frank Rowand
2016-06-16 17:51 ` Frank Rowand
2016-06-17 7:51 ` Mathieu Malaterre
2016-06-17 7:51 ` Mathieu Malaterre
2016-06-24 20:38 ` Rob Herring
2016-06-24 20:38 ` Rob Herring
2016-07-20 6:03 ` Mathieu Malaterre
2016-07-22 19:58 ` Rob Herring
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.