aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2015-02-13 17:36:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:36 -0500
commitdfeb0750b630b72b5d4fb2461bc7179eceb54666 (patch)
tree22af2116c4b061fd8ce268f78f56696e0a21c5c1
parent75287a677ba1beab7ca0db948468f44eb23a709f (diff)
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>
-rw-r--r--fs/kernfs/dir.c20
-rw-r--r--fs/kernfs/file.c4
-rw-r--r--fs/sysfs/file.c2
-rw-r--r--include/linux/kernfs.h7
-rw-r--r--kernel/cgroup.c2
5 files changed, 12 insertions, 23 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 35e40879860a..6acc9648f986 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -411,8 +411,9 @@ void kernfs_put(struct kernfs_node *kn)
411 411
412 if (kernfs_type(kn) == KERNFS_LINK) 412 if (kernfs_type(kn) == KERNFS_LINK)
413 kernfs_put(kn->symlink.target_kn); 413 kernfs_put(kn->symlink.target_kn);
414 if (!(kn->flags & KERNFS_STATIC_NAME)) 414
415 kfree_const(kn->name); 415 kfree_const(kn->name);
416
416 if (kn->iattr) { 417 if (kn->iattr) {
417 if (kn->iattr->ia_secdata) 418 if (kn->iattr->ia_secdata)
418 security_release_secctx(kn->iattr->ia_secdata, 419 security_release_secctx(kn->iattr->ia_secdata,
@@ -506,15 +507,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
506 const char *name, umode_t mode, 507 const char *name, umode_t mode,
507 unsigned flags) 508 unsigned flags)
508{ 509{
509 const char *dup_name = NULL;
510 struct kernfs_node *kn; 510 struct kernfs_node *kn;
511 int ret; 511 int ret;
512 512
513 if (!(flags & KERNFS_STATIC_NAME)) { 513 name = kstrdup_const(name, GFP_KERNEL);
514 name = dup_name = kstrdup_const(name, GFP_KERNEL); 514 if (!name)
515 if (!name) 515 return NULL;
516 return NULL;
517 }
518 516
519 kn = kmem_cache_zalloc(kernfs_node_cache, GFP_KERNEL); 517 kn = kmem_cache_zalloc(kernfs_node_cache, GFP_KERNEL);
520 if (!kn) 518 if (!kn)
@@ -538,7 +536,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
538 err_out2: 536 err_out2:
539 kmem_cache_free(kernfs_node_cache, kn); 537 kmem_cache_free(kernfs_node_cache, kn);
540 err_out1: 538 err_out1:
541 kfree_const(dup_name); 539 kfree_const(name);
542 return NULL; 540 return NULL;
543} 541}
544 542
@@ -1285,9 +1283,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
1285 1283
1286 kn->ns = new_ns; 1284 kn->ns = new_ns;
1287 if (new_name) { 1285 if (new_name) {
1288 if (!(kn->flags & KERNFS_STATIC_NAME)) 1286 old_name = kn->name;
1289 old_name = kn->name;
1290 kn->flags &= ~KERNFS_STATIC_NAME;
1291 kn->name = new_name; 1287 kn->name = new_name;
1292 } 1288 }
1293 1289
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index ddc9f9612f16..b684e8a132e6 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -901,7 +901,6 @@ const struct file_operations kernfs_file_fops = {
901 * @ops: kernfs operations for the file 901 * @ops: kernfs operations for the file
902 * @priv: private data for the file 902 * @priv: private data for the file
903 * @ns: optional namespace tag of the file 903 * @ns: optional namespace tag of the file
904 * @name_is_static: don't copy file name
905 * @key: lockdep key for the file's active_ref, %NULL to disable lockdep 904 * @key: lockdep key for the file's active_ref, %NULL to disable lockdep
906 * 905 *
907 * Returns the created node on success, ERR_PTR() value on error. 906 * Returns the created node on success, ERR_PTR() value on error.
@@ -911,7 +910,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
911 umode_t mode, loff_t size, 910 umode_t mode, loff_t size,
912 const struct kernfs_ops *ops, 911 const struct kernfs_ops *ops,
913 void *priv, const void *ns, 912 void *priv, const void *ns,
914 bool name_is_static,
915 struct lock_class_key *key) 913 struct lock_class_key *key)
916{ 914{
917 struct kernfs_node *kn; 915 struct kernfs_node *kn;
@@ -919,8 +917,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
919 int rc; 917 int rc;
920 918
921 flags = KERNFS_FILE; 919 flags = KERNFS_FILE;
922 if (name_is_static)
923 flags |= KERNFS_STATIC_NAME;
924 920
925 kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags); 921 kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG, flags);
926 if (!kn) 922 if (!kn)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index dfe928a9540f..7c2867b44141 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -295,7 +295,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent,
295 key = attr->key ?: (struct lock_class_key *)&attr->skey; 295 key = attr->key ?: (struct lock_class_key *)&attr->skey;
296#endif 296#endif
297 kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops, 297 kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops,
298 (void *)attr, ns, true, key); 298 (void *)attr, ns, key);
299 if (IS_ERR(kn)) { 299 if (IS_ERR(kn)) {
300 if (PTR_ERR(kn) == -EEXIST) 300 if (PTR_ERR(kn) == -EEXIST)
301 sysfs_warn_dup(parent, attr->name); 301 sysfs_warn_dup(parent, attr->name);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index d4e01b358341..71ecdab1671b 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -43,7 +43,6 @@ enum kernfs_node_flag {
43 KERNFS_HAS_SEQ_SHOW = 0x0040, 43 KERNFS_HAS_SEQ_SHOW = 0x0040,
44 KERNFS_HAS_MMAP = 0x0080, 44 KERNFS_HAS_MMAP = 0x0080,
45 KERNFS_LOCKDEP = 0x0100, 45 KERNFS_LOCKDEP = 0x0100,
46 KERNFS_STATIC_NAME = 0x0200,
47 KERNFS_SUICIDAL = 0x0400, 46 KERNFS_SUICIDAL = 0x0400,
48 KERNFS_SUICIDED = 0x0800, 47 KERNFS_SUICIDED = 0x0800,
49}; 48};
@@ -291,7 +290,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
291 umode_t mode, loff_t size, 290 umode_t mode, loff_t size,
292 const struct kernfs_ops *ops, 291 const struct kernfs_ops *ops,
293 void *priv, const void *ns, 292 void *priv, const void *ns,
294 bool name_is_static,
295 struct lock_class_key *key); 293 struct lock_class_key *key);
296struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 294struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
297 const char *name, 295 const char *name,
@@ -369,8 +367,7 @@ kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
369static inline struct kernfs_node * 367static inline struct kernfs_node *
370__kernfs_create_file(struct kernfs_node *parent, const char *name, 368__kernfs_create_file(struct kernfs_node *parent, const char *name,
371 umode_t mode, loff_t size, const struct kernfs_ops *ops, 369 umode_t mode, loff_t size, const struct kernfs_ops *ops,
372 void *priv, const void *ns, bool name_is_static, 370 void *priv, const void *ns, struct lock_class_key *key)
373 struct lock_class_key *key)
374{ return ERR_PTR(-ENOSYS); } 371{ return ERR_PTR(-ENOSYS); }
375 372
376static inline struct kernfs_node * 373static inline struct kernfs_node *
@@ -439,7 +436,7 @@ kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
439 key = (struct lock_class_key *)&ops->lockdep_key; 436 key = (struct lock_class_key *)&ops->lockdep_key;
440#endif 437#endif
441 return __kernfs_create_file(parent, name, mode, size, ops, priv, ns, 438 return __kernfs_create_file(parent, name, mode, size, ops, priv, ns,
442 false, key); 439 key);
443} 440}
444 441
445static inline struct kernfs_node * 442static inline struct kernfs_node *
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d5f6ec251fb2..29a7b2cc593e 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3077,7 +3077,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft)
3077#endif 3077#endif
3078 kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name), 3078 kn = __kernfs_create_file(cgrp->kn, cgroup_file_name(cgrp, cft, name),
3079 cgroup_file_mode(cft), 0, cft->kf_ops, cft, 3079 cgroup_file_mode(cft), 0, cft->kf_ops, cft,
3080 NULL, false, key); 3080 NULL, key);
3081 if (IS_ERR(kn)) 3081 if (IS_ERR(kn))
3082 return PTR_ERR(kn); 3082 return PTR_ERR(kn);
3083 3083