[PATCH] selinuxfs cleanups: sel_make_bools
[powerpc.git] / security / selinux / selinuxfs.c
index cc78208..ab7c993 100644 (file)
@@ -970,7 +970,7 @@ out:
        return ret;
 err:
        kfree(values);
-       d_genocide(dir);
+       sel_remove_bools(dir);
        ret = -ENOMEM;
        goto out;
 }
@@ -1181,6 +1181,8 @@ static int sel_make_dir(struct super_block *sb, struct dentry *dentry)
        }
        inode->i_op = &simple_dir_inode_operations;
        inode->i_fop = &simple_dir_operations;
+       /* directory inodes start off with i_nlink == 2 (for "." entry) */
+       inode->i_nlink++;
        d_add(dentry, inode);
 out:
        return ret;
@@ -1211,30 +1213,31 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
        };
        ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
        if (ret)
-               return ret;
+               goto err;
 
        dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
-       if (!dentry)
-               return -ENOMEM;
+       if (!dentry) {
+               ret = -ENOMEM;
+               goto err;
+       }
 
-       inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
-       if (!inode)
-               goto out;
-       inode->i_op = &simple_dir_inode_operations;
-       inode->i_fop = &simple_dir_operations;
-       d_add(dentry, inode);
-       bool_dir = dentry;
-       ret = sel_make_bools();
+       ret = sel_make_dir(sb, dentry);
        if (ret)
-               goto out;
+               goto err;
+
+       bool_dir = dentry;
 
        dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
-       if (!dentry)
-               return -ENOMEM;
+       if (!dentry) {
+               ret = -ENOMEM;
+               goto err;
+       }
 
        inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
-       if (!inode)
-               goto out;
+       if (!inode) {
+               ret = -ENOMEM;
+               goto err;
+       }
        isec = (struct inode_security_struct*)inode->i_security;
        isec->sid = SECINITSID_DEVNULL;
        isec->sclass = SECCLASS_CHR_FILE;
@@ -1245,22 +1248,23 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
        selinux_null = dentry;
 
        dentry = d_alloc_name(sb->s_root, "avc");
-       if (!dentry)
-               return -ENOMEM;
+       if (!dentry) {
+               ret = -ENOMEM;
+               goto err;
+       }
 
        ret = sel_make_dir(sb, dentry);
        if (ret)
-               goto out;
+               goto err;
 
        ret = sel_make_avc_files(dentry);
        if (ret)
-               goto out;
-
-       return 0;
+               goto err;
 out:
-       dput(dentry);
+       return ret;
+err:
        printk(KERN_ERR "%s:  failed while creating inodes\n", __FUNCTION__);
-       return -ENOMEM;
+       goto out;
 }
 
 static struct super_block *sel_get_sb(struct file_system_type *fs_type,