aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r--fs/sysfs/dir.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index bbf3525fd222..06dff2c30c9b 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -219,14 +219,16 @@ static int create_dir(struct kobject *kobj, struct dentry *parent,
219 goto out_drop; 219 goto out_drop;
220 sd->s_elem.dir.kobj = kobj; 220 sd->s_elem.dir.kobj = kobj;
221 221
222 inode = sysfs_new_inode(sd); 222 inode = sysfs_get_inode(sd);
223 if (!inode) 223 if (!inode)
224 goto out_sput; 224 goto out_sput;
225 225
226 inode->i_op = &sysfs_dir_inode_operations; 226 if (inode->i_state & I_NEW) {
227 inode->i_fop = &sysfs_dir_operations; 227 inode->i_op = &sysfs_dir_inode_operations;
228 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 228 inode->i_fop = &sysfs_dir_operations;
229 inc_nlink(inode); 229 /* directory inodes start off with i_nlink == 2 (for ".") */
230 inc_nlink(inode);
231 }
230 232
231 /* link in */ 233 /* link in */
232 error = -EEXIST; 234 error = -EEXIST;
@@ -310,20 +312,23 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
310 return NULL; 312 return NULL;
311 313
312 /* attach dentry and inode */ 314 /* attach dentry and inode */
313 inode = sysfs_new_inode(sd); 315 inode = sysfs_get_inode(sd);
314 if (!inode) 316 if (!inode)
315 return ERR_PTR(-ENOMEM); 317 return ERR_PTR(-ENOMEM);
316 318
317 /* initialize inode according to type */ 319 if (inode->i_state & I_NEW) {
318 if (sd->s_type & SYSFS_KOBJ_ATTR) { 320 /* initialize inode according to type */
319 inode->i_size = PAGE_SIZE; 321 if (sd->s_type & SYSFS_KOBJ_ATTR) {
320 inode->i_fop = &sysfs_file_operations; 322 inode->i_size = PAGE_SIZE;
321 } else if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) { 323 inode->i_fop = &sysfs_file_operations;
322 struct bin_attribute *bin_attr = sd->s_elem.bin_attr.bin_attr; 324 } else if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) {
323 inode->i_size = bin_attr->size; 325 struct bin_attribute *bin_attr =
324 inode->i_fop = &bin_fops; 326 sd->s_elem.bin_attr.bin_attr;
325 } else if (sd->s_type & SYSFS_KOBJ_LINK) 327 inode->i_size = bin_attr->size;
326 inode->i_op = &sysfs_symlink_inode_operations; 328 inode->i_fop = &bin_fops;
329 } else if (sd->s_type & SYSFS_KOBJ_LINK)
330 inode->i_op = &sysfs_symlink_inode_operations;
331 }
327 332
328 sysfs_instantiate(dentry, inode); 333 sysfs_instantiate(dentry, inode);
329 sysfs_attach_dentry(sd, dentry); 334 sysfs_attach_dentry(sd, dentry);