diff options
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r-- | fs/sysfs/dir.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 5da8da806660..9504d4cb63eb 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -883,14 +883,10 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) | |||
883 | struct sysfs_dirent *sd; | 883 | struct sysfs_dirent *sd; |
884 | struct dentry *parent = NULL; | 884 | struct dentry *parent = NULL; |
885 | struct dentry *old_dentry = NULL, *new_dentry = NULL; | 885 | struct dentry *old_dentry = NULL, *new_dentry = NULL; |
886 | struct sysfs_dirent *parent_sd; | ||
887 | const char *dup_name = NULL; | 886 | const char *dup_name = NULL; |
888 | int error; | 887 | int error; |
889 | 888 | ||
890 | if (!kobj->parent) | 889 | /* get the original dentry */ |
891 | return -EINVAL; | ||
892 | |||
893 | /* get dentries */ | ||
894 | sd = kobj->sd; | 890 | sd = kobj->sd; |
895 | old_dentry = sysfs_get_dentry(sd); | 891 | old_dentry = sysfs_get_dentry(sd); |
896 | if (IS_ERR(old_dentry)) { | 892 | if (IS_ERR(old_dentry)) { |
@@ -898,12 +894,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) | |||
898 | goto out_dput; | 894 | goto out_dput; |
899 | } | 895 | } |
900 | 896 | ||
901 | parent_sd = kobj->parent->sd; | 897 | parent = old_dentry->d_parent; |
902 | parent = sysfs_get_dentry(parent_sd); | ||
903 | if (IS_ERR(parent)) { | ||
904 | error = PTR_ERR(parent); | ||
905 | goto out_dput; | ||
906 | } | ||
907 | 898 | ||
908 | /* lock parent and get dentry for new name */ | 899 | /* lock parent and get dentry for new name */ |
909 | mutex_lock(&parent->d_inode->i_mutex); | 900 | mutex_lock(&parent->d_inode->i_mutex); |
@@ -933,22 +924,14 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) | |||
933 | goto out_drop; | 924 | goto out_drop; |
934 | 925 | ||
935 | mutex_lock(&sysfs_mutex); | 926 | mutex_lock(&sysfs_mutex); |
936 | |||
937 | dup_name = sd->s_name; | 927 | dup_name = sd->s_name; |
938 | sd->s_name = new_name; | 928 | sd->s_name = new_name; |
929 | mutex_unlock(&sysfs_mutex); | ||
939 | 930 | ||
940 | /* move under the new parent */ | 931 | /* rename */ |
941 | d_add(new_dentry, NULL); | 932 | d_add(new_dentry, NULL); |
942 | d_move(sd->s_dentry, new_dentry); | 933 | d_move(sd->s_dentry, new_dentry); |
943 | 934 | ||
944 | sysfs_unlink_sibling(sd); | ||
945 | sysfs_get(parent_sd); | ||
946 | sysfs_put(sd->s_parent); | ||
947 | sd->s_parent = parent_sd; | ||
948 | sysfs_link_sibling(sd); | ||
949 | |||
950 | mutex_unlock(&sysfs_mutex); | ||
951 | |||
952 | error = 0; | 935 | error = 0; |
953 | goto out_unlock; | 936 | goto out_unlock; |
954 | 937 | ||
@@ -958,7 +941,6 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) | |||
958 | mutex_unlock(&parent->d_inode->i_mutex); | 941 | mutex_unlock(&parent->d_inode->i_mutex); |
959 | out_dput: | 942 | out_dput: |
960 | kfree(dup_name); | 943 | kfree(dup_name); |
961 | dput(parent); | ||
962 | dput(old_dentry); | 944 | dput(old_dentry); |
963 | dput(new_dentry); | 945 | dput(new_dentry); |
964 | return error; | 946 | return error; |