]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sysfs: introduce [__]sysfs_remove()
authorTejun Heo <tj@kernel.org>
Wed, 18 Sep 2013 21:15:38 +0000 (17:15 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Oct 2013 23:38:52 +0000 (16:38 -0700)
Given a sysfs_dirent, there is no reason to have multiple versions of
removal functions.  A function which removes the specified
sysfs_dirent and its descendants is enough.

This patch intorduces [__}sysfs_remove() which replaces all internal
variations of removal functions.  This will be the only removal
function in the planned new sysfs_dirent based interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/dir.c
fs/sysfs/group.c
fs/sysfs/inode.c
fs/sysfs/sysfs.h

index 0cdfd8128d3e5199eaf37e7dd7f2c54030100b68..b518afd0d11e06b6c563a2aa55922829e0946242 100644 (file)
@@ -545,7 +545,8 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
  *     LOCKING:
  *     Determined by sysfs_addrm_start().
  */
-void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
+static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
+                            struct sysfs_dirent *sd)
 {
        struct sysfs_inode_attrs *ps_iattr;
 
@@ -775,20 +776,6 @@ const struct inode_operations sysfs_dir_inode_operations = {
        .setxattr       = sysfs_setxattr,
 };
 
-static void remove_dir(struct sysfs_dirent *sd)
-{
-       struct sysfs_addrm_cxt acxt;
-
-       sysfs_addrm_start(&acxt);
-       sysfs_remove_one(&acxt, sd);
-       sysfs_addrm_finish(&acxt);
-}
-
-void sysfs_remove_subdir(struct sysfs_dirent *sd)
-{
-       remove_dir(sd);
-}
-
 static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
 {
        struct sysfs_dirent *last;
@@ -844,25 +831,36 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
        return pos->s_parent;
 }
 
-static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
+void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
 {
-       struct sysfs_addrm_cxt acxt;
        struct sysfs_dirent *pos, *next;
 
-       if (!dir_sd)
+       if (!sd)
                return;
 
-       pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
-       sysfs_addrm_start(&acxt);
+       pr_debug("sysfs %s: removing\n", sd->s_name);
 
        next = NULL;
        do {
                pos = next;
-               next = sysfs_next_descendant_post(pos, dir_sd);
+               next = sysfs_next_descendant_post(pos, sd);
                if (pos)
-                       sysfs_remove_one(&acxt, pos);
+                       sysfs_remove_one(acxt, pos);
        } while (next);
+}
 
+/**
+ * sysfs_remove - remove a sysfs_dirent recursively
+ * @sd: the sysfs_dirent to remove
+ *
+ * Remove @sd along with all its subdirectories and files.
+ */
+void sysfs_remove(struct sysfs_dirent *sd)
+{
+       struct sysfs_addrm_cxt acxt;
+
+       sysfs_addrm_start(&acxt);
+       __sysfs_remove(&acxt, sd);
        sysfs_addrm_finish(&acxt);
 }
 
@@ -882,7 +880,10 @@ void sysfs_remove_dir(struct kobject *kobj)
        kobj->sd = NULL;
        spin_unlock(&sysfs_assoc_lock);
 
-       __sysfs_remove_dir(sd);
+       if (sd) {
+               WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR);
+               sysfs_remove(sd);
+       }
 }
 
 int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
index 2dae55c4f7dce9c577321794bdc08e65e473dfea..1898a10e38ce8ccef26a687882c637f349ac5b29 100644 (file)
@@ -111,7 +111,7 @@ static int internal_create_group(struct kobject *kobj, int update,
        error = create_files(sd, kobj, grp, update);
        if (error) {
                if (grp->name)
-                       sysfs_remove_subdir(sd);
+                       sysfs_remove(sd);
        }
        sysfs_put(sd);
        return error;
@@ -219,7 +219,7 @@ void sysfs_remove_group(struct kobject *kobj,
 
        remove_files(sd, kobj, grp);
        if (grp->name)
-               sysfs_remove_subdir(sd);
+               sysfs_remove(sd);
 
        sysfs_put(sd);
 }
index 364c8873fbda054bf51c5966365d20606dc35007..63f755ef71dd70b1d33df9994759a126ca0d802a 100644 (file)
@@ -330,7 +330,7 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
 
        sd = sysfs_find_dirent(dir_sd, name, ns);
        if (sd)
-               sysfs_remove_one(&acxt, sd);
+               __sysfs_remove(&acxt, sd);
 
        sysfs_addrm_finish(&acxt);
 
index 4d1154411cdbdd8bafc81c4bcf83f9fc46cbffa3..4b1d8258b0710ee3cff8ad02d686f7c1b76a33ee 100644 (file)
@@ -158,7 +158,8 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
                    struct sysfs_dirent *parent_sd);
 int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
                  struct sysfs_dirent *parent_sd);
-void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
+void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
+void sysfs_remove(struct sysfs_dirent *sd);
 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
 
 struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
@@ -170,7 +171,6 @@ void release_sysfs_dirent(struct sysfs_dirent *sd);
 
 int sysfs_create_subdir(struct kobject *kobj, const char *name,
                        struct sysfs_dirent **p_sd);
-void sysfs_remove_subdir(struct sysfs_dirent *sd);
 
 int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
                 const char *new_name, const void *new_ns);