Commit ff869de7 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

sysfs: simplify sysfs_rename_dir()

With the shadow directories gone, sysfs_rename_dir() can be simplified.

* parent doesn't need to be grabbed separately.  Just access
  old_dentry->d_parent.

* parent sd can never change.  Remove code to move under the new
  parent.

* Massage comments a bit.
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Acked-by: default avatarCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a7a04754
...@@ -883,14 +883,10 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) ...@@ -883,14 +883,10 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
struct sysfs_dirent *sd; struct sysfs_dirent *sd;
struct dentry *parent = NULL; struct dentry *parent = NULL;
struct dentry *old_dentry = NULL, *new_dentry = NULL; struct dentry *old_dentry = NULL, *new_dentry = NULL;
struct sysfs_dirent *parent_sd;
const char *dup_name = NULL; const char *dup_name = NULL;
int error; int error;
if (!kobj->parent) /* get the original dentry */
return -EINVAL;
/* get dentries */
sd = kobj->sd; sd = kobj->sd;
old_dentry = sysfs_get_dentry(sd); old_dentry = sysfs_get_dentry(sd);
if (IS_ERR(old_dentry)) { if (IS_ERR(old_dentry)) {
...@@ -898,12 +894,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) ...@@ -898,12 +894,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
goto out_dput; goto out_dput;
} }
parent_sd = kobj->parent->sd; parent = old_dentry->d_parent;
parent = sysfs_get_dentry(parent_sd);
if (IS_ERR(parent)) {
error = PTR_ERR(parent);
goto out_dput;
}
/* lock parent and get dentry for new name */ /* lock parent and get dentry for new name */
mutex_lock(&parent->d_inode->i_mutex); mutex_lock(&parent->d_inode->i_mutex);
...@@ -933,22 +924,14 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) ...@@ -933,22 +924,14 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
goto out_drop; goto out_drop;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
dup_name = sd->s_name; dup_name = sd->s_name;
sd->s_name = new_name; sd->s_name = new_name;
mutex_unlock(&sysfs_mutex);
/* move under the new parent */ /* rename */
d_add(new_dentry, NULL); d_add(new_dentry, NULL);
d_move(sd->s_dentry, new_dentry); d_move(sd->s_dentry, new_dentry);
sysfs_unlink_sibling(sd);
sysfs_get(parent_sd);
sysfs_put(sd->s_parent);
sd->s_parent = parent_sd;
sysfs_link_sibling(sd);
mutex_unlock(&sysfs_mutex);
error = 0; error = 0;
goto out_unlock; goto out_unlock;
...@@ -958,7 +941,6 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) ...@@ -958,7 +941,6 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
mutex_unlock(&parent->d_inode->i_mutex); mutex_unlock(&parent->d_inode->i_mutex);
out_dput: out_dput:
kfree(dup_name); kfree(dup_name);
dput(parent);
dput(old_dentry); dput(old_dentry);
dput(new_dentry); dput(new_dentry);
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment