From: James Morris This patch consolidates several occurrences of duplicated code into a new libfs function simple_alloc_dentry(). Signed-off-by: James Morris Signed-off-by: Andrew Morton --- 25-akpm/drivers/misc/ibmasm/ibmasmfs.c | 13 ++----------- 25-akpm/drivers/oprofile/oprofilefs.c | 14 ++++---------- 25-akpm/drivers/usb/gadget/inode.c | 6 +----- 25-akpm/fs/libfs.c | 17 ++++++++++++----- 25-akpm/include/linux/fs.h | 1 + 25-akpm/net/sunrpc/rpc_pipe.c | 6 +----- 25-akpm/security/selinux/selinuxfs.c | 17 +++-------------- 7 files changed, 24 insertions(+), 50 deletions(-) diff -puN drivers/misc/ibmasm/ibmasmfs.c~add-simple_alloc_dentry-to-libfs drivers/misc/ibmasm/ibmasmfs.c --- 25/drivers/misc/ibmasm/ibmasmfs.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.808013648 -0700 +++ 25-akpm/drivers/misc/ibmasm/ibmasmfs.c 2004-10-16 01:33:00.828010608 -0700 @@ -173,13 +173,8 @@ static struct dentry *ibmasmfs_create_fi { struct dentry *dentry; struct inode *inode; - struct qstr qname; - qname.name = name; - qname.len = strlen (name); - qname.hash = full_name_hash(name, qname.len); - - dentry = d_alloc(parent, &qname); + dentry = simple_alloc_dentry(parent, name); if (!dentry) return NULL; @@ -202,12 +197,8 @@ static struct dentry *ibmasmfs_create_di { struct dentry *dentry; struct inode *inode; - struct qstr qname; - qname.name = name; - qname.len = strlen (name); - qname.hash = full_name_hash(name, qname.len); - dentry = d_alloc(parent, &qname); + dentry = simple_alloc_dentry(parent, name); if (!dentry) return NULL; diff -puN drivers/oprofile/oprofilefs.c~add-simple_alloc_dentry-to-libfs drivers/oprofile/oprofilefs.c --- 25/drivers/oprofile/oprofilefs.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.809013496 -0700 +++ 25-akpm/drivers/oprofile/oprofilefs.c 2004-10-16 01:33:00.828010608 -0700 @@ -135,11 +135,8 @@ static struct dentry * __oprofilefs_crea { struct dentry * dentry; struct inode * inode; - struct qstr qname; - qname.name = name; - qname.len = strlen(name); - qname.hash = full_name_hash(qname.name, qname.len); - dentry = d_alloc(root, &qname); + + dentry = simple_alloc_dentry(root, name); if (!dentry) return NULL; inode = oprofilefs_get_inode(sb, S_IFREG | perm); @@ -228,11 +225,8 @@ struct dentry * oprofilefs_mkdir(struct { struct dentry * dentry; struct inode * inode; - struct qstr qname; - qname.name = name; - qname.len = strlen(name); - qname.hash = full_name_hash(qname.name, qname.len); - dentry = d_alloc(root, &qname); + + dentry = simple_alloc_dentry(root, name); if (!dentry) return NULL; inode = oprofilefs_get_inode(sb, S_IFDIR | 0755); diff -puN drivers/usb/gadget/inode.c~add-simple_alloc_dentry-to-libfs drivers/usb/gadget/inode.c --- 25/drivers/usb/gadget/inode.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.811013192 -0700 +++ 25-akpm/drivers/usb/gadget/inode.c 2004-10-16 01:33:00.830010304 -0700 @@ -1981,12 +1981,8 @@ gadgetfs_create_file (struct super_block { struct dentry *dentry; struct inode *inode; - struct qstr qname; - qname.name = name; - qname.len = strlen (name); - qname.hash = full_name_hash (qname.name, qname.len); - dentry = d_alloc (sb->s_root, &qname); + dentry = simple_alloc_dentry (sb->s_root, name); if (!dentry) return NULL; diff -puN fs/libfs.c~add-simple_alloc_dentry-to-libfs fs/libfs.c --- 25/fs/libfs.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.812013040 -0700 +++ 25-akpm/fs/libfs.c 2004-10-16 01:33:00.831010152 -0700 @@ -362,6 +362,16 @@ int simple_commit_write(struct file *fil return 0; } +struct dentry *simple_alloc_dentry(struct dentry *parent, const char *name) +{ + struct qstr q; + + q.name = name; + q.len = strlen(name); + q.hash = full_name_hash(q.name, q.len); + return d_alloc(parent, &q); +} + int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files) { static struct super_operations s_ops = {.statfs = simple_statfs}; @@ -391,13 +401,9 @@ int simple_fill_super(struct super_block return -ENOMEM; } for (i = 0; !files->name || files->name[0]; i++, files++) { - struct qstr name; if (!files->name) continue; - name.name = files->name; - name.len = strlen(name.name); - name.hash = full_name_hash(name.name, name.len); - dentry = d_alloc(root, &name); + dentry = simple_alloc_dentry(root, files->name); if (!dentry) goto out; inode = new_inode(s); @@ -530,6 +536,7 @@ EXPORT_SYMBOL(simple_commit_write); EXPORT_SYMBOL(simple_dir_inode_operations); EXPORT_SYMBOL(simple_dir_operations); EXPORT_SYMBOL(simple_empty); +EXPORT_SYMBOL(simple_alloc_dentry); EXPORT_SYMBOL(simple_fill_super); EXPORT_SYMBOL(simple_getattr); EXPORT_SYMBOL(simple_link); diff -puN include/linux/fs.h~add-simple_alloc_dentry-to-libfs include/linux/fs.h --- 25/include/linux/fs.h~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.814012736 -0700 +++ 25-akpm/include/linux/fs.h 2004-10-16 01:33:00.832010000 -0700 @@ -1647,6 +1647,7 @@ extern ssize_t generic_read_dir(struct f extern struct file_operations simple_dir_operations; extern struct inode_operations simple_dir_inode_operations; struct tree_descr { char *name; struct file_operations *ops; int mode; }; +struct dentry *simple_alloc_dentry(struct dentry *, const char *); extern int simple_fill_super(struct super_block *, int, struct tree_descr *); extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count); extern void simple_release_fs(struct vfsmount **mount, int *count); diff -puN net/sunrpc/rpc_pipe.c~add-simple_alloc_dentry-to-libfs net/sunrpc/rpc_pipe.c --- 25/net/sunrpc/rpc_pipe.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.823011368 -0700 +++ 25-akpm/net/sunrpc/rpc_pipe.c 2004-10-16 01:33:00.833009848 -0700 @@ -523,16 +523,12 @@ rpc_populate(struct dentry *parent, { struct inode *inode, *dir = parent->d_inode; void *private = RPC_I(dir)->private; - struct qstr name; struct dentry *dentry; int mode, i; down(&dir->i_sem); for (i = start; i < eof; i++) { - name.name = files[i].name; - name.len = strlen(name.name); - name.hash = full_name_hash(name.name, name.len); - dentry = d_alloc(parent, &name); + dentry = simple_alloc_dentry(parent, files[i].name); if (!dentry) goto out_bad; mode = files[i].mode; diff -puN security/selinux/selinuxfs.c~add-simple_alloc_dentry-to-libfs security/selinux/selinuxfs.c --- 25/security/selinux/selinuxfs.c~add-simple_alloc_dentry-to-libfs 2004-10-16 01:33:00.824011216 -0700 +++ 25-akpm/security/selinux/selinuxfs.c 2004-10-16 01:33:00.834009696 -0700 @@ -818,7 +818,6 @@ static int sel_make_bools(void) struct dentry *dir = bool_dir; struct inode *inode = NULL; struct inode_security_struct *isec; - struct qstr qname; char **names = NULL, *page; int num; int *values = NULL; @@ -838,10 +837,7 @@ static int sel_make_bools(void) goto out; for (i = 0; i < num; i++) { - qname.name = names[i]; - qname.len = strlen(qname.name); - qname.hash = full_name_hash(qname.name, qname.len); - dentry = d_alloc(dir, &qname); + dentry = simple_alloc_dentry(dir, names[i]); if (!dentry) { ret = -ENOMEM; goto err; @@ -896,7 +892,6 @@ static int sel_fill_super(struct super_b int ret; struct dentry *dentry; struct inode *inode; - struct qstr qname; struct inode_security_struct *isec; static struct tree_descr selinux_files[] = { @@ -917,10 +912,7 @@ static int sel_fill_super(struct super_b if (ret) return ret; - qname.name = BOOL_DIR_NAME; - qname.len = strlen(qname.name); - qname.hash = full_name_hash(qname.name, qname.len); - dentry = d_alloc(sb->s_root, &qname); + dentry = simple_alloc_dentry(sb->s_root, BOOL_DIR_NAME); if (!dentry) return -ENOMEM; @@ -935,10 +927,7 @@ static int sel_fill_super(struct super_b if (ret) goto out; - qname.name = NULL_FILE_NAME; - qname.len = strlen(qname.name); - qname.hash = full_name_hash(qname.name, qname.len); - dentry = d_alloc(sb->s_root, &qname); + dentry = simple_alloc_dentry(sb->s_root, NULL_FILE_NAME); if (!dentry) return -ENOMEM; _