sysfs: fix parent refcounting during rename and move
authorTejun Heo <htejun@gmail.com>
Wed, 13 Jun 2007 18:45:17 +0000 (03:45 +0900)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 11 Jul 2007 23:09:07 +0000 (16:09 -0700)
Parent reference wasn't properly transferred during rename and move.
Fix it.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/sysfs/dir.c

index a63d12e4be5683ab6ceb932f21c21a2ff917066e..a26e3db89432edbea5810298b126def0b864fd61 100644 (file)
@@ -497,6 +497,9 @@ int sysfs_rename_dir(struct kobject * kobj, struct dentry *new_parent,
        d_move(kobj->dentry, new_dentry);
 
        list_del_init(&sd->s_sibling);
+       sysfs_get(parent_sd);
+       sysfs_put(sd->s_parent);
+       sd->s_parent = parent_sd;
        list_add(&sd->s_sibling, &parent_sd->s_children);
 
        error = 0;
@@ -550,6 +553,9 @@ again:
 
        /* Remove from old parent's list and insert into new parent's list. */
        list_del_init(&sd->s_sibling);
+       sysfs_get(new_parent_sd);
+       sysfs_put(sd->s_parent);
+       sd->s_parent = new_parent_sd;
        list_add(&sd->s_sibling, &new_parent_sd->s_children);
 
 out: