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.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 1c3dc5d01ccd..36b6c796d4d5 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -289,22 +289,7 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
289{ 289{
290 struct sysfs_dirent * sd = dentry->d_fsdata; 290 struct sysfs_dirent * sd = dentry->d_fsdata;
291 291
292 if (sd) { 292 sysfs_put(sd);
293 /* sd->s_dentry is protected with sysfs_assoc_lock.
294 * This allows sysfs_drop_dentry() to dereference it.
295 */
296 spin_lock(&sysfs_assoc_lock);
297
298 /* The dentry might have been deleted or another
299 * lookup could have happened updating sd->s_dentry to
300 * point the new dentry. Ignore if it isn't pointing
301 * to this dentry.
302 */
303 if (sd->s_dentry == dentry)
304 sd->s_dentry = NULL;
305 spin_unlock(&sysfs_assoc_lock);
306 sysfs_put(sd);
307 }
308 iput(inode); 293 iput(inode);
309} 294}
310 295
@@ -352,9 +337,6 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
352 * @sd: target sysfs_dirent 337 * @sd: target sysfs_dirent
353 * @dentry: dentry to associate 338 * @dentry: dentry to associate
354 * 339 *
355 * Associate @sd with @dentry. This is protected by
356 * sysfs_assoc_lock to avoid race with sysfs_d_iput().
357 *
358 * LOCKING: 340 * LOCKING:
359 * mutex_lock(sysfs_mutex) 341 * mutex_lock(sysfs_mutex)
360 */ 342 */
@@ -362,12 +344,6 @@ static void sysfs_attach_dentry(struct sysfs_dirent *sd, struct dentry *dentry)
362{ 344{
363 dentry->d_op = &sysfs_dentry_ops; 345 dentry->d_op = &sysfs_dentry_ops;
364 dentry->d_fsdata = sysfs_get(sd); 346 dentry->d_fsdata = sysfs_get(sd);
365
366 /* protect sd->s_dentry against sysfs_d_iput */
367 spin_lock(&sysfs_assoc_lock);
368 sd->s_dentry = dentry;
369 spin_unlock(&sysfs_assoc_lock);
370
371 d_rehash(dentry); 347 d_rehash(dentry);
372} 348}
373 349
@@ -846,7 +822,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
846 822
847 /* rename */ 823 /* rename */
848 d_add(new_dentry, NULL); 824 d_add(new_dentry, NULL);
849 d_move(sd->s_dentry, new_dentry); 825 d_move(old_dentry, new_dentry);
850 826
851 error = 0; 827 error = 0;
852 goto out_unlock; 828 goto out_unlock;
@@ -881,7 +857,7 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
881 error = PTR_ERR(old_dentry); 857 error = PTR_ERR(old_dentry);
882 goto out_dput; 858 goto out_dput;
883 } 859 }
884 old_parent = sd->s_parent->s_dentry; 860 old_parent = old_dentry->d_parent;
885 861
886 new_parent = sysfs_get_dentry(new_parent_sd); 862 new_parent = sysfs_get_dentry(new_parent_sd);
887 if (IS_ERR(new_parent)) { 863 if (IS_ERR(new_parent)) {
@@ -907,7 +883,7 @@ again:
907 } else 883 } else
908 error = 0; 884 error = 0;
909 d_add(new_dentry, NULL); 885 d_add(new_dentry, NULL);
910 d_move(sd->s_dentry, new_dentry); 886 d_move(old_dentry, new_dentry);
911 dput(new_dentry); 887 dput(new_dentry);
912 888
913 /* Remove from old parent's list and insert into new parent's list. */ 889 /* Remove from old parent's list and insert into new parent's list. */