From: Christoph Hellwig 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 Cc: Greg KH Cc: Paul Jackson Signed-off-by: Andrew Morton --- drivers/usb/core/inode.c | 13 +------------ fs/debugfs/inode.c | 12 +----------- fs/sysfs/dir.c | 5 +++-- fs/sysfs/file.c | 5 +++-- fs/sysfs/group.c | 4 +++- fs/sysfs/inode.c | 10 ---------- fs/sysfs/sysfs.h | 1 - kernel/cpuset.c | 8 +------- 8 files changed, 12 insertions(+), 46 deletions(-) diff -puN drivers/usb/core/inode.c~remove-duplicate-get_dentry-functions-in-various-places drivers/usb/core/inode.c --- 25/drivers/usb/core/inode.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/drivers/usb/core/inode.c Fri May 6 15:39:59 2005 @@ -453,17 +453,6 @@ static int usbfs_fill_super(struct super return 0; } -static struct dentry * get_dentry(struct dentry *parent, const char *name) -{ - struct qstr qstr; - - qstr.name = name; - qstr.len = strlen(name); - qstr.hash = full_name_hash(name,qstr.len); - return lookup_hash(&qstr,parent); -} - - /* * fs_create_by_name - create a file, given a name * @name: name of file @@ -496,7 +485,7 @@ static int fs_create_by_name (const char *dentry = NULL; down(&parent->d_inode->i_sem); - *dentry = get_dentry (parent, name); + *dentry = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(dentry)) { if ((mode & S_IFMT) == S_IFDIR) error = usbfs_mkdir (parent->d_inode, *dentry, mode); diff -puN fs/debugfs/inode.c~remove-duplicate-get_dentry-functions-in-various-places fs/debugfs/inode.c --- 25/fs/debugfs/inode.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/debugfs/inode.c Fri May 6 15:39:59 2005 @@ -110,16 +110,6 @@ static int debug_fill_super(struct super return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); } -static struct dentry * get_dentry(struct dentry *parent, const char *name) -{ - struct qstr qstr; - - qstr.name = name; - qstr.len = strlen(name); - qstr.hash = full_name_hash(name,qstr.len); - return lookup_hash(&qstr,parent); -} - static struct super_block *debug_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) @@ -157,7 +147,7 @@ static int debugfs_create_by_name(const *dentry = NULL; down(&parent->d_inode->i_sem); - *dentry = get_dentry (parent, name); + *dentry = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(dentry)) { if ((mode & S_IFMT) == S_IFDIR) error = debugfs_mkdir(parent->d_inode, *dentry, mode); diff -puN fs/sysfs/dir.c~remove-duplicate-get_dentry-functions-in-various-places fs/sysfs/dir.c --- 25/fs/sysfs/dir.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/sysfs/dir.c Fri May 6 15:39:59 2005 @@ -8,6 +8,7 @@ #include #include #include +#include #include "sysfs.h" DECLARE_RWSEM(sysfs_rename_sem); @@ -99,7 +100,7 @@ static int create_dir(struct kobject * k umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; down(&p->d_inode->i_sem); - *d = sysfs_get_dentry(p,n); + *d = lookup_one_len(n, p, strlen(n)); if (!IS_ERR(*d)) { error = sysfs_create(*d, mode, init_dir); if (!error) { @@ -309,7 +310,7 @@ int sysfs_rename_dir(struct kobject * ko down(&parent->d_inode->i_sem); - new_dentry = sysfs_get_dentry(parent, new_name); + new_dentry = lookup_one_len(new_name, parent, strlen(new_name)); if (!IS_ERR(new_dentry)) { if (!new_dentry->d_inode) { error = kobject_set_name(kobj, "%s", new_name); diff -puN fs/sysfs/file.c~remove-duplicate-get_dentry-functions-in-various-places fs/sysfs/file.c --- 25/fs/sysfs/file.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/sysfs/file.c Fri May 6 15:39:59 2005 @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -400,7 +401,7 @@ int sysfs_update_file(struct kobject * k int res = -ENOENT; down(&dir->d_inode->i_sem); - victim = sysfs_get_dentry(dir, attr->name); + victim = lookup_one_len(attr->name, dir, strlen(attr->name)); if (!IS_ERR(victim)) { /* make sure dentry is really there */ if (victim->d_inode && @@ -443,7 +444,7 @@ int sysfs_chmod_file(struct kobject *kob int res = -ENOENT; down(&dir->d_inode->i_sem); - victim = sysfs_get_dentry(dir, attr->name); + victim = lookup_one_len(attr->name, dir, strlen(attr->name)); if (!IS_ERR(victim)) { if (victim->d_inode && (victim->d_parent->d_inode == dir->d_inode)) { diff -puN fs/sysfs/group.c~remove-duplicate-get_dentry-functions-in-various-places fs/sysfs/group.c --- 25/fs/sysfs/group.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/sysfs/group.c Fri May 6 15:39:59 2005 @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "sysfs.h" @@ -68,7 +69,8 @@ void sysfs_remove_group(struct kobject * struct dentry * dir; if (grp->name) - dir = sysfs_get_dentry(kobj->dentry,grp->name); + dir = lookup_one_len(grp->name, kobj->dentry, + strlen(grp->name)); else dir = dget(kobj->dentry); diff -puN fs/sysfs/inode.c~remove-duplicate-get_dentry-functions-in-various-places fs/sysfs/inode.c --- 25/fs/sysfs/inode.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/sysfs/inode.c Fri May 6 15:39:59 2005 @@ -76,16 +76,6 @@ int sysfs_create(struct dentry * dentry, return error; } -struct dentry * sysfs_get_dentry(struct dentry * parent, const char * name) -{ - struct qstr qstr; - - qstr.name = name; - qstr.len = strlen(name); - qstr.hash = full_name_hash(name,qstr.len); - return lookup_hash(&qstr,parent); -} - /* * Get the name for corresponding element represented by the given sysfs_dirent */ diff -puN fs/sysfs/sysfs.h~remove-duplicate-get_dentry-functions-in-various-places fs/sysfs/sysfs.h --- 25/fs/sysfs/sysfs.h~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/fs/sysfs/sysfs.h Fri May 6 15:39:59 2005 @@ -7,7 +7,6 @@ extern int sysfs_create(struct dentry *, extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, umode_t, int); -extern struct dentry * sysfs_get_dentry(struct dentry *, const char *); extern int sysfs_add_file(struct dentry *, const struct attribute *, int); extern void sysfs_hash_and_remove(struct dentry * dir, const char * name); diff -puN kernel/cpuset.c~remove-duplicate-get_dentry-functions-in-various-places kernel/cpuset.c --- 25/kernel/cpuset.c~remove-duplicate-get_dentry-functions-in-various-places Fri May 6 15:39:59 2005 +++ 25-akpm/kernel/cpuset.c Fri May 6 15:39:59 2005 @@ -229,13 +229,7 @@ static struct dentry_operations cpuset_d static struct dentry *cpuset_get_dentry(struct dentry *parent, const char *name) { - struct qstr qstr; - struct dentry *d; - - qstr.name = name; - qstr.len = strlen(name); - qstr.hash = full_name_hash(name, qstr.len); - d = lookup_hash(&qstr, parent); + struct dentry *d = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(d)) d->d_op = &cpuset_dops; return d; _