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

kernfs: remove KERNFS_STATIC_NAME

When a new kernfs node is created, KERNFS_STATIC_NAME is used to avoid
making a separate copy of its name. It's currently only used for sysfs
attributes whose filenames are required to stay accessible and unchanged.
There are rare exceptions where these names are allocated and formatted
dynamically but for the vast majority of cases they're consts in the
rodata section.

Now that kernfs is converted to use kstrdup_const() and kfree_const(),
there's little point in keeping KERNFS_STATIC_NAME around. Remove it.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tejun Heo and committed by
Linus Torvalds
dfeb0750 75287a67

+12 -23
+8 -12
fs/kernfs/dir.c
··· 411 411 412 412 if (kernfs_type(kn) == KERNFS_LINK) 413 413 kernfs_put(kn->symlink.target_kn); 414 - if (!(kn->flags & KERNFS_STATIC_NAME)) 415 - kfree_const(kn->name); 414 + 415 + kfree_const(kn->name); 416 + 416 417 if (kn->iattr) { 417 418 if (kn->iattr->ia_secdata) 418 419 security_release_secctx(kn->iattr->ia_secdata, ··· 507 506 const char *name, umode_t mode, 508 507 unsigned flags) 509 508 { 510 - const char *dup_name = NULL; 511 509 struct kernfs_node *kn; 512 510 int ret; 513 511 514 - if (!(flags & KERNFS_STATIC_NAME)) { 515 - name = dup_name = kstrdup_const(name, GFP_KERNEL); 516 - if (!name) 517 - return NULL; 518 - } 512 + name = kstrdup_const(name, GFP_KERNEL); 513 + if (!name) 514 + return NULL; 519 515 520 516 kn = kmem_cache_zalloc(kernfs_node_cache, GFP_KERNEL); 521 517 if (!kn) ··· 536 538 err_out2: 537 539 kmem_cache_free(kernfs_node_cache, kn); 538 540 err_out1: 539 - kfree_const(dup_name); 541 + kfree_const(name); 540 542 return NULL; 541 543 } 542 544 ··· 1283 1285 1284 1286 kn->ns = new_ns; 1285 1287 if (new_name) { 1286 - if (!(kn->flags & KERNFS_STATIC_NAME)) 1287 - old_name = kn->name; 1288 - kn->flags &= ~KERNFS_STATIC_NAME; 1288 + old_name = kn->name; 1289 1289 kn->name = new_name; 1290 1290 } 1291 1291
-4
fs/kernfs/file.c
··· 901 901 * @ops: kernfs operations for the file 902 902 * @priv: private data for the file 903 903 * @ns: optional namespace tag of the file 904 - * @name_is_static: don't copy file name 905 904 * @key: lockdep key for the file's active_ref, %NULL to disable lockdep 906 905 * 907 906 * Returns the created node on success, ERR_PTR() value on error. ··· 910 911 umode_t mode, loff_t size, 911 912 const struct kernfs_ops *ops, 912 913 void *priv, const void *ns, 913 - bool name_is_static, 914 914 struct lock_class_key *key) 915 915 { 916 916 struct kernfs_node *kn; ··· 917 919 int rc; 918 920 919 921 flags = KERNFS_FILE; 920 - if (name_is_static) 921 - flags |= KERNFS_STATIC_NAME; 922 922 923 923 kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags); 924 924 if (!kn)
+1 -1
fs/sysfs/file.c
··· 295 295 key = attr->key ?: (struct lock_class_key *)&attr->skey; 296 296 #endif 297 297 kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops, 298 - (void *)attr, ns, true, key); 298 + (void *)attr, ns, key); 299 299 if (IS_ERR(kn)) { 300 300 if (PTR_ERR(kn) == -EEXIST) 301 301 sysfs_warn_dup(parent, attr->name);
+2 -5
include/linux/kernfs.h
··· 43 43 KERNFS_HAS_SEQ_SHOW = 0x0040, 44 44 KERNFS_HAS_MMAP = 0x0080, 45 45 KERNFS_LOCKDEP = 0x0100, 46 - KERNFS_STATIC_NAME = 0x0200, 47 46 KERNFS_SUICIDAL = 0x0400, 48 47 KERNFS_SUICIDED = 0x0800, 49 48 }; ··· 290 291 umode_t mode, loff_t size, 291 292 const struct kernfs_ops *ops, 292 293 void *priv, const void *ns, 293 - bool name_is_static, 294 294 struct lock_class_key *key); 295 295 struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 296 296 const char *name, ··· 367 369 static inline struct kernfs_node * 368 370 __kernfs_create_file(struct kernfs_node *parent, const char *name, 369 371 umode_t mode, loff_t size, const struct kernfs_ops *ops, 370 - void *priv, const void *ns, bool name_is_static, 371 - struct lock_class_key *key) 372 + void *priv, const void *ns, struct lock_class_key *key) 372 373 { return ERR_PTR(-ENOSYS); } 373 374 374 375 static inline struct kernfs_node * ··· 436 439 key = (struct lock_class_key *)&ops->lockdep_key; 437 440 #endif 438 441 return __kernfs_create_file(parent, name, mode, size, ops, priv, ns, 439 - false, key); 442 + key); 440 443 } 441 444 442 445 static inline struct kernfs_node *
+1 -1
kernel/cgroup.c
··· 3077 3077 #endif 3078 3078 kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), 3079 3079 cgroup_file_mode(cft), 0, cft->kf_ops, cft, 3080 - NULL, false, key); 3080 + NULL, key); 3081 3081 if (IS_ERR(kn)) 3082 3082 return PTR_ERR(kn); 3083 3083