Commit 75287a67 authored by Andrzej Hajda's avatar Andrzej Hajda Committed by Linus Torvalds

kernfs: convert node name allocation to kstrdup_const

sysfs frequently performs duplication of strings located in read-only
memory section.  Replacing kstrdup by kstrdup_const allows to avoid such
operations.
Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Cc: Greg KH <greg@kroah.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a4bb1e43
...@@ -412,7 +412,7 @@ void kernfs_put(struct kernfs_node *kn) ...@@ -412,7 +412,7 @@ void kernfs_put(struct kernfs_node *kn)
if (kernfs_type(kn) == KERNFS_LINK) if (kernfs_type(kn) == KERNFS_LINK)
kernfs_put(kn->symlink.target_kn); kernfs_put(kn->symlink.target_kn);
if (!(kn->flags & KERNFS_STATIC_NAME)) if (!(kn->flags & KERNFS_STATIC_NAME))
kfree(kn->name); kfree_const(kn->name);
if (kn->iattr) { if (kn->iattr) {
if (kn->iattr->ia_secdata) if (kn->iattr->ia_secdata)
security_release_secctx(kn->iattr->ia_secdata, security_release_secctx(kn->iattr->ia_secdata,
...@@ -506,12 +506,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, ...@@ -506,12 +506,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
const char *name, umode_t mode, const char *name, umode_t mode,
unsigned flags) unsigned flags)
{ {
char *dup_name = NULL; const char *dup_name = NULL;
struct kernfs_node *kn; struct kernfs_node *kn;
int ret; int ret;
if (!(flags & KERNFS_STATIC_NAME)) { if (!(flags & KERNFS_STATIC_NAME)) {
name = dup_name = kstrdup(name, GFP_KERNEL); name = dup_name = kstrdup_const(name, GFP_KERNEL);
if (!name) if (!name)
return NULL; return NULL;
} }
...@@ -538,7 +538,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, ...@@ -538,7 +538,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
err_out2: err_out2:
kmem_cache_free(kernfs_node_cache, kn); kmem_cache_free(kernfs_node_cache, kn);
err_out1: err_out1:
kfree(dup_name); kfree_const(dup_name);
return NULL; return NULL;
} }
...@@ -1264,7 +1264,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, ...@@ -1264,7 +1264,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
/* rename kernfs_node */ /* rename kernfs_node */
if (strcmp(kn->name, new_name) != 0) { if (strcmp(kn->name, new_name) != 0) {
error = -ENOMEM; error = -ENOMEM;
new_name = kstrdup(new_name, GFP_KERNEL); new_name = kstrdup_const(new_name, GFP_KERNEL);
if (!new_name) if (!new_name)
goto out; goto out;
} else { } else {
...@@ -1297,7 +1297,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, ...@@ -1297,7 +1297,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
kernfs_link_sibling(kn); kernfs_link_sibling(kn);
kernfs_put(old_parent); kernfs_put(old_parent);
kfree(old_name); kfree_const(old_name);
error = 0; error = 0;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment