Skip to content

Commit 250f7c3

Browse files
htejungregkh
authored andcommitted
sysfs: introduce [__]sysfs_remove()
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>
1 parent bcdde7e commit 250f7c3

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
545545
* LOCKING:
546546
* Determined by sysfs_addrm_start().
547547
*/
548-
void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
548+
static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
549+
struct sysfs_dirent *sd)
549550
{
550551
struct sysfs_inode_attrs *ps_iattr;
551552

@@ -775,20 +776,6 @@ const struct inode_operations sysfs_dir_inode_operations = {
775776
.setxattr = sysfs_setxattr,
776777
};
777778

778-
static void remove_dir(struct sysfs_dirent *sd)
779-
{
780-
struct sysfs_addrm_cxt acxt;
781-
782-
sysfs_addrm_start(&acxt);
783-
sysfs_remove_one(&acxt, sd);
784-
sysfs_addrm_finish(&acxt);
785-
}
786-
787-
void sysfs_remove_subdir(struct sysfs_dirent *sd)
788-
{
789-
remove_dir(sd);
790-
}
791-
792779
static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
793780
{
794781
struct sysfs_dirent *last;
@@ -844,25 +831,36 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
844831
return pos->s_parent;
845832
}
846833

847-
static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
834+
void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
848835
{
849-
struct sysfs_addrm_cxt acxt;
850836
struct sysfs_dirent *pos, *next;
851837

852-
if (!dir_sd)
838+
if (!sd)
853839
return;
854840

855-
pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
856-
sysfs_addrm_start(&acxt);
841+
pr_debug("sysfs %s: removing\n", sd->s_name);
857842

858843
next = NULL;
859844
do {
860845
pos = next;
861-
next = sysfs_next_descendant_post(pos, dir_sd);
846+
next = sysfs_next_descendant_post(pos, sd);
862847
if (pos)
863-
sysfs_remove_one(&acxt, pos);
848+
sysfs_remove_one(acxt, pos);
864849
} while (next);
850+
}
865851

852+
/**
853+
* sysfs_remove - remove a sysfs_dirent recursively
854+
* @sd: the sysfs_dirent to remove
855+
*
856+
* Remove @sd along with all its subdirectories and files.
857+
*/
858+
void sysfs_remove(struct sysfs_dirent *sd)
859+
{
860+
struct sysfs_addrm_cxt acxt;
861+
862+
sysfs_addrm_start(&acxt);
863+
__sysfs_remove(&acxt, sd);
866864
sysfs_addrm_finish(&acxt);
867865
}
868866

@@ -882,7 +880,10 @@ void sysfs_remove_dir(struct kobject *kobj)
882880
kobj->sd = NULL;
883881
spin_unlock(&sysfs_assoc_lock);
884882

885-
__sysfs_remove_dir(sd);
883+
if (sd) {
884+
WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR);
885+
sysfs_remove(sd);
886+
}
886887
}
887888

888889
int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,

‎fs/sysfs/group.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int internal_create_group(struct kobject *kobj, int update,
111111
error = create_files(sd, kobj, grp, update);
112112
if (error) {
113113
if (grp->name)
114-
sysfs_remove_subdir(sd);
114+
sysfs_remove(sd);
115115
}
116116
sysfs_put(sd);
117117
return error;
@@ -219,7 +219,7 @@ void sysfs_remove_group(struct kobject *kobj,
219219

220220
remove_files(sd, kobj, grp);
221221
if (grp->name)
222-
sysfs_remove_subdir(sd);
222+
sysfs_remove(sd);
223223

224224
sysfs_put(sd);
225225
}

‎fs/sysfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
330330

331331
sd = sysfs_find_dirent(dir_sd, name, ns);
332332
if (sd)
333-
sysfs_remove_one(&acxt, sd);
333+
__sysfs_remove(&acxt, sd);
334334

335335
sysfs_addrm_finish(&acxt);
336336

‎fs/sysfs/sysfs.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
158158
struct sysfs_dirent *parent_sd);
159159
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
160160
struct sysfs_dirent *parent_sd);
161-
void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
161+
void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
162+
void sysfs_remove(struct sysfs_dirent *sd);
162163
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
163164

164165
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
@@ -170,7 +171,6 @@ void release_sysfs_dirent(struct sysfs_dirent *sd);
170171

171172
int sysfs_create_subdir(struct kobject *kobj, const char *name,
172173
struct sysfs_dirent **p_sd);
173-
void sysfs_remove_subdir(struct sysfs_dirent *sd);
174174

175175
int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
176176
const char *new_name, const void *new_ns);

0 commit comments

Comments
 (0)