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

[PATCH] remove duplicate get_dentry functions in various places

Various filesystem drivers have grown a get_dentry() function that's a
duplicate of lookup_one_len, except that it doesn't take a maximum length
argument and doesn't check for \0 or / in the passed in filename.

Switch all these places to use lookup_one_len.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: Greg KH <greg@kroah.com>
Cc: Paul Jackson <pj@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Christoph Hellwig and committed by
Linus Torvalds
5f45f1a7 ac20427e

+12 -46
+1 -12
drivers/usb/core/inode.c
··· 453 453 return 0; 454 454 } 455 455 456 - static struct dentry * get_dentry(struct dentry *parent, const char *name) 457 - { 458 - struct qstr qstr; 459 - 460 - qstr.name = name; 461 - qstr.len = strlen(name); 462 - qstr.hash = full_name_hash(name,qstr.len); 463 - return lookup_hash(&qstr,parent); 464 - } 465 - 466 - 467 456 /* 468 457 * fs_create_by_name - create a file, given a name 469 458 * @name: name of file ··· 485 496 486 497 *dentry = NULL; 487 498 down(&parent->d_inode->i_sem); 488 - *dentry = get_dentry (parent, name); 499 + *dentry = lookup_one_len(name, parent, strlen(name)); 489 500 if (!IS_ERR(dentry)) { 490 501 if ((mode & S_IFMT) == S_IFDIR) 491 502 error = usbfs_mkdir (parent->d_inode, *dentry, mode);
+1 -11
fs/debugfs/inode.c
··· 110 110 return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); 111 111 } 112 112 113 - static struct dentry * get_dentry(struct dentry *parent, const char *name) 114 - { 115 - struct qstr qstr; 116 - 117 - qstr.name = name; 118 - qstr.len = strlen(name); 119 - qstr.hash = full_name_hash(name,qstr.len); 120 - return lookup_hash(&qstr,parent); 121 - } 122 - 123 113 static struct super_block *debug_get_sb(struct file_system_type *fs_type, 124 114 int flags, const char *dev_name, 125 115 void *data) ··· 147 157 148 158 *dentry = NULL; 149 159 down(&parent->d_inode->i_sem); 150 - *dentry = get_dentry (parent, name); 160 + *dentry = lookup_one_len(name, parent, strlen(name)); 151 161 if (!IS_ERR(dentry)) { 152 162 if ((mode & S_IFMT) == S_IFDIR) 153 163 error = debugfs_mkdir(parent->d_inode, *dentry, mode);
+3 -2
fs/sysfs/dir.c
··· 8 8 #include <linux/mount.h> 9 9 #include <linux/module.h> 10 10 #include <linux/kobject.h> 11 + #include <linux/namei.h> 11 12 #include "sysfs.h" 12 13 13 14 DECLARE_RWSEM(sysfs_rename_sem); ··· 100 99 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; 101 100 102 101 down(&p->d_inode->i_sem); 103 - *d = sysfs_get_dentry(p,n); 102 + *d = lookup_one_len(n, p, strlen(n)); 104 103 if (!IS_ERR(*d)) { 105 104 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR); 106 105 if (!error) { ··· 316 315 317 316 down(&parent->d_inode->i_sem); 318 317 319 - new_dentry = sysfs_get_dentry(parent, new_name); 318 + new_dentry = lookup_one_len(new_name, parent, strlen(new_name)); 320 319 if (!IS_ERR(new_dentry)) { 321 320 if (!new_dentry->d_inode) { 322 321 error = kobject_set_name(kobj, "%s", new_name);
+3 -2
fs/sysfs/file.c
··· 5 5 #include <linux/module.h> 6 6 #include <linux/dnotify.h> 7 7 #include <linux/kobject.h> 8 + #include <linux/namei.h> 8 9 #include <asm/uaccess.h> 9 10 #include <asm/semaphore.h> 10 11 ··· 401 400 int res = -ENOENT; 402 401 403 402 down(&dir->d_inode->i_sem); 404 - victim = sysfs_get_dentry(dir, attr->name); 403 + victim = lookup_one_len(attr->name, dir, strlen(attr->name)); 405 404 if (!IS_ERR(victim)) { 406 405 /* make sure dentry is really there */ 407 406 if (victim->d_inode && ··· 444 443 int res = -ENOENT; 445 444 446 445 down(&dir->d_inode->i_sem); 447 - victim = sysfs_get_dentry(dir, attr->name); 446 + victim = lookup_one_len(attr->name, dir, strlen(attr->name)); 448 447 if (!IS_ERR(victim)) { 449 448 if (victim->d_inode && 450 449 (victim->d_parent->d_inode == dir->d_inode)) {
+3 -1
fs/sysfs/group.c
··· 11 11 #include <linux/kobject.h> 12 12 #include <linux/module.h> 13 13 #include <linux/dcache.h> 14 + #include <linux/namei.h> 14 15 #include <linux/err.h> 15 16 #include "sysfs.h" 16 17 ··· 69 68 struct dentry * dir; 70 69 71 70 if (grp->name) 72 - dir = sysfs_get_dentry(kobj->dentry,grp->name); 71 + dir = lookup_one_len(grp->name, kobj->dentry, 72 + strlen(grp->name)); 73 73 else 74 74 dir = dget(kobj->dentry); 75 75
-10
fs/sysfs/inode.c
··· 166 166 return error; 167 167 } 168 168 169 - struct dentry * sysfs_get_dentry(struct dentry * parent, const char * name) 170 - { 171 - struct qstr qstr; 172 - 173 - qstr.name = name; 174 - qstr.len = strlen(name); 175 - qstr.hash = full_name_hash(name,qstr.len); 176 - return lookup_hash(&qstr,parent); 177 - } 178 - 179 169 /* 180 170 * Get the name for corresponding element represented by the given sysfs_dirent 181 171 */
-1
fs/sysfs/sysfs.h
··· 7 7 8 8 extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, 9 9 umode_t, int); 10 - extern struct dentry * sysfs_get_dentry(struct dentry *, const char *); 11 10 12 11 extern int sysfs_add_file(struct dentry *, const struct attribute *, int); 13 12 extern void sysfs_hash_and_remove(struct dentry * dir, const char * name);
+1 -7
kernel/cpuset.c
··· 228 228 229 229 static struct dentry *cpuset_get_dentry(struct dentry *parent, const char *name) 230 230 { 231 - struct qstr qstr; 232 - struct dentry *d; 233 - 234 - qstr.name = name; 235 - qstr.len = strlen(name); 236 - qstr.hash = full_name_hash(name, qstr.len); 237 - d = lookup_hash(&qstr, parent); 231 + struct dentry *d = lookup_one_len(name, parent, strlen(name)); 238 232 if (!IS_ERR(d)) 239 233 d->d_op = &cpuset_dops; 240 234 return d;