From: Tejun Heo <htejun@gmail.com>
To: gregkh@suse.de, dmitry.torokhov@gmail.com,
cornelia.huck@de.ibm.com, oneukum@suse.de, rpurdie@rpsys.net,
stern@rowland.harvard.edu, maneesh@in.ibm.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 09/21] sysfs: flatten and fix sysfs_rename_dir() error handling
Date: Sat, 28 Apr 2007 22:39:41 +0900 [thread overview]
Message-ID: <11777675813047-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11777675753460-git-send-email-htejun@gmail.com>
Error handling in sysfs_rename_dir() was broken.
* When lookup_one_len() fails, 0 is returned.
* If parent inode check fails, returns with inode mutex and rename
rwsem held.
This patch fixes the above bugs and flattens error handling such that
it's more readable and easier to modify.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
fs/sysfs/dir.c | 73 +++++++++++++++++++++++++++++++------------------------
1 files changed, 41 insertions(+), 32 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 0dca2c4..df057da 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -434,8 +434,9 @@ void sysfs_remove_dir(struct kobject * kobj)
int sysfs_rename_dir(struct kobject * kobj, struct dentry *new_parent,
const char *new_name)
{
- int error = 0;
+ int error;
struct dentry * new_dentry;
+ struct sysfs_dirent *sd, *parent_sd;
if (!new_parent)
return -EFAULT;
@@ -444,40 +445,48 @@ int sysfs_rename_dir(struct kobject * kobj, struct dentry *new_parent,
mutex_lock(&new_parent->d_inode->i_mutex);
new_dentry = lookup_one_len(new_name, new_parent, strlen(new_name));
- if (!IS_ERR(new_dentry)) {
- /* By allowing two different directories with the
- * same d_parent we allow this routine to move
- * between different shadows of the same directory
- */
- if (kobj->dentry->d_parent->d_inode != new_parent->d_inode)
- return -EINVAL;
- else if (new_dentry->d_parent->d_inode != new_parent->d_inode)
- error = -EINVAL;
- else if (new_dentry == kobj->dentry)
- error = -EINVAL;
- else if (!new_dentry->d_inode) {
- error = kobject_set_name(kobj, "%s", new_name);
- if (!error) {
- struct sysfs_dirent *sd, *parent_sd;
-
- d_add(new_dentry, NULL);
- d_move(kobj->dentry, new_dentry);
-
- sd = kobj->dentry->d_fsdata;
- parent_sd = new_parent->d_fsdata;
-
- list_del_init(&sd->s_sibling);
- list_add(&sd->s_sibling, &parent_sd->s_children);
- }
- else
- d_drop(new_dentry);
- } else
- error = -EEXIST;
- dput(new_dentry);
+ if (IS_ERR(new_dentry)) {
+ error = PTR_ERR(new_dentry);
+ goto out_unlock;
}
+
+ /* By allowing two different directories with the same
+ * d_parent we allow this routine to move between different
+ * shadows of the same directory
+ */
+ error = -EINVAL;
+ if (kobj->dentry->d_parent->d_inode != new_parent->d_inode ||
+ new_dentry->d_parent->d_inode != new_parent->d_inode ||
+ new_dentry == kobj->dentry)
+ goto out_dput;
+
+ error = -EEXIST;
+ if (new_dentry->d_inode)
+ goto out_dput;
+
+ error = kobject_set_name(kobj, "%s", new_name);
+ if (error)
+ goto out_drop;
+
+ d_add(new_dentry, NULL);
+ d_move(kobj->dentry, new_dentry);
+
+ sd = kobj->dentry->d_fsdata;
+ parent_sd = new_parent->d_fsdata;
+
+ list_del_init(&sd->s_sibling);
+ list_add(&sd->s_sibling, &parent_sd->s_children);
+
+ error = 0;
+ goto out_unlock;
+
+ out_drop:
+ d_drop(new_dentry);
+ out_dput:
+ dput(new_dentry);
+ out_unlock:
mutex_unlock(&new_parent->d_inode->i_mutex);
up_write(&sysfs_rename_sem);
-
return error;
}
--
1.5.0.3
next prev parent reply other threads:[~2007-04-28 13:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-28 13:39 [PATCHSET] sysfs: sysfs rework, take #2 Tejun Heo
2007-04-28 13:39 ` [PATCH 01/21] idr: fix obscure bug in allocation path Tejun Heo
2007-04-28 13:39 ` [PATCH 02/21] idr: separate out idr_mark_full() Tejun Heo
2007-04-28 13:39 ` [PATCH 06/21] sysfs: make sysfs_put() ignore NULL sd Tejun Heo
2007-04-28 13:39 ` [PATCH 03/21] ida: implement idr based id allocator Tejun Heo
2007-04-28 13:39 ` [PATCH 05/21] sysfs: allocate inode number using ida Tejun Heo
2007-04-28 13:39 ` [PATCH 04/21] sysfs: move release_sysfs_dirent() to dir.c Tejun Heo
2007-04-28 13:39 ` [PATCH 07/21] sysfs: fix error handling in binattr write() Tejun Heo
2007-04-28 13:39 ` [PATCH 11/21] sysfs: add sysfs_dirent->s_parent Tejun Heo
2007-04-28 13:39 ` [PATCH 12/21] sysfs: add sysfs_dirent->s_name Tejun Heo
2007-04-28 13:39 ` [PATCH 10/21] sysfs: consolidate sysfs_dirent creation functions Tejun Heo
2007-04-28 13:39 ` Tejun Heo [this message]
2007-04-28 13:39 ` [PATCH 08/21] sysfs: flatten cleanup paths in sysfs_add_link() and create_dir() Tejun Heo
2007-04-28 13:39 ` [PATCH 14/21] sysfs: implement kobj_sysfs_assoc_lock Tejun Heo
2007-04-28 13:39 ` [PATCH 16/21] sysfs: implement bin_buffer Tejun Heo
2007-05-01 14:25 ` Satyam Sharma
[not found] ` <463753DB.2060101@gmail.com>
2007-05-01 19:37 ` Satyam Sharma
2007-05-01 20:04 ` Satyam Sharma
2007-05-02 11:29 ` Tejun Heo
2007-04-28 13:39 ` [PATCH 19/21] sysfs: kill unnecessary attribute->owner Tejun Heo
2007-04-28 13:39 ` [PATCH 17/21] sysfs: implement sysfs_dirent active reference and immediate disconnect Tejun Heo
2007-04-28 13:39 ` [PATCH 18/21] sysfs: kill attribute file orphaning Tejun Heo
2007-04-28 13:39 ` [PATCH 15/21] sysfs: reimplement symlink using sysfs_dirent tree Tejun Heo
2007-04-28 13:39 ` [PATCH 20/21] sysfs: separate out sysfs_attach_dentry() Tejun Heo
2007-04-28 13:39 ` [PATCH 13/21] sysfs: make sysfs_dirent->s_element a union Tejun Heo
2007-04-28 13:39 ` [PATCH 21/21] sysfs: reimplement syfs_drop_dentry() Tejun Heo
2007-04-28 14:28 ` [PATCHSET] sysfs: sysfs rework, take #2 Alan Stern
2007-04-28 16:06 ` Tejun Heo
2007-05-02 12:38 ` Cornelia Huck
2007-05-02 13:04 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11777675813047-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cornelia.huck@de.ibm.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=maneesh@in.ibm.com \
--cc=oneukum@suse.de \
--cc=rpurdie@rpsys.net \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox