Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Andrzej 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: Tejun Heo <tj@kernel.org>
Cc: Greg KH <greg@kroah.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrzej Hajda and committed by
Linus Torvalds
75287a67 a4bb1e43

+6 -6
+6 -6
fs/kernfs/dir.c
··· 412 412 if (kernfs_type(kn) == KERNFS_LINK) 413 413 kernfs_put(kn->symlink.target_kn); 414 414 if (!(kn->flags & KERNFS_STATIC_NAME)) 415 - kfree(kn->name); 415 + kfree_const(kn->name); 416 416 if (kn->iattr) { 417 417 if (kn->iattr->ia_secdata) 418 418 security_release_secctx(kn->iattr->ia_secdata, ··· 506 506 const char *name, umode_t mode, 507 507 unsigned flags) 508 508 { 509 - char *dup_name = NULL; 509 + const char *dup_name = NULL; 510 510 struct kernfs_node *kn; 511 511 int ret; 512 512 513 513 if (!(flags & KERNFS_STATIC_NAME)) { 514 - name = dup_name = kstrdup(name, GFP_KERNEL); 514 + name = dup_name = kstrdup_const(name, GFP_KERNEL); 515 515 if (!name) 516 516 return NULL; 517 517 } ··· 538 538 err_out2: 539 539 kmem_cache_free(kernfs_node_cache, kn); 540 540 err_out1: 541 - kfree(dup_name); 541 + kfree_const(dup_name); 542 542 return NULL; 543 543 } 544 544 ··· 1264 1264 /* rename kernfs_node */ 1265 1265 if (strcmp(kn->name, new_name) != 0) { 1266 1266 error = -ENOMEM; 1267 - new_name = kstrdup(new_name, GFP_KERNEL); 1267 + new_name = kstrdup_const(new_name, GFP_KERNEL); 1268 1268 if (!new_name) 1269 1269 goto out; 1270 1270 } else { ··· 1297 1297 kernfs_link_sibling(kn); 1298 1298 1299 1299 kernfs_put(old_parent); 1300 - kfree(old_name); 1300 + kfree_const(old_name); 1301 1301 1302 1302 error = 0; 1303 1303 out: