OSDN Git Service

sysfs: Create mountpoints with sysfs_create_mount_point
[android-x86/kernel.git] / security / selinux / selinuxfs.c
index 33db1ad..ea81533 100644 (file)
@@ -152,7 +152,7 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,
                goto out;
 
        /* No partial writes. */
-       length = EINVAL;
+       length = -EINVAL;
        if (*ppos != 0)
                goto out;
 
@@ -1195,30 +1195,8 @@ static const struct file_operations sel_commit_bools_ops = {
 
 static void sel_remove_entries(struct dentry *de)
 {
-       struct list_head *node;
-
-       spin_lock(&de->d_lock);
-       node = de->d_subdirs.next;
-       while (node != &de->d_subdirs) {
-               struct dentry *d = list_entry(node, struct dentry, d_child);
-
-               spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
-               list_del_init(node);
-
-               if (d->d_inode) {
-                       dget_dlock(d);
-                       spin_unlock(&de->d_lock);
-                       spin_unlock(&d->d_lock);
-                       d_delete(d);
-                       simple_unlink(de->d_inode, d);
-                       dput(d);
-                       spin_lock(&de->d_lock);
-               } else
-                       spin_unlock(&d->d_lock);
-               node = de->d_subdirs.next;
-       }
-
-       spin_unlock(&de->d_lock);
+       d_genocide(de);
+       shrink_dcache_parent(de);
 }
 
 #define BOOL_DIR_NAME "booleans"
@@ -1668,37 +1646,13 @@ static int sel_make_class_dir_entries(char *classname, int index,
        return rc;
 }
 
-static void sel_remove_classes(void)
-{
-       struct list_head *class_node;
-
-       list_for_each(class_node, &class_dir->d_subdirs) {
-               struct dentry *class_subdir = list_entry(class_node,
-                                       struct dentry, d_child);
-               struct list_head *class_subdir_node;
-
-               list_for_each(class_subdir_node, &class_subdir->d_subdirs) {
-                       struct dentry *d = list_entry(class_subdir_node,
-                                               struct dentry, d_child);
-
-                       if (d->d_inode)
-                               if (d->d_inode->i_mode & S_IFDIR)
-                                       sel_remove_entries(d);
-               }
-
-               sel_remove_entries(class_subdir);
-       }
-
-       sel_remove_entries(class_dir);
-}
-
 static int sel_make_classes(void)
 {
        int rc, nclasses, i;
        char **classes;
 
        /* delete any existing entries */
-       sel_remove_classes();
+       sel_remove_entries(class_dir);
 
        rc = security_get_classes(&classes, &nclasses);
        if (rc)
@@ -1899,7 +1853,6 @@ static struct file_system_type sel_fs_type = {
 };
 
 struct vfsmount *selinuxfs_mount;
-static struct kobject *selinuxfs_kobj;
 
 static int __init init_sel_fs(void)
 {
@@ -1908,13 +1861,13 @@ static int __init init_sel_fs(void)
        if (!selinux_enabled)
                return 0;
 
-       selinuxfs_kobj = kobject_create_and_add("selinux", fs_kobj);
-       if (!selinuxfs_kobj)
-               return -ENOMEM;
+       err = sysfs_create_mount_point(fs_kobj, "selinux");
+       if (err)
+               return err;
 
        err = register_filesystem(&sel_fs_type);
        if (err) {
-               kobject_put(selinuxfs_kobj);
+               sysfs_remove_mount_point(fs_kobj, "selinux");
                return err;
        }
 
@@ -1933,7 +1886,7 @@ __initcall(init_sel_fs);
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
 void exit_sel_fs(void)
 {
-       kobject_put(selinuxfs_kobj);
+       sysfs_remove_mount_point(fs_kobj, "selinux");
        kern_unmount(selinuxfs_mount);
        unregister_filesystem(&sel_fs_type);
 }