[PATCH 2/2] CIFS: Fix ERR_PTR dereference in cifs_get_root

Jeff Layton jlayton at redhat.com
Thu Aug 25 14:39:54 UTC 2011


From: Pavel Shilovsky <piastryyy at gmail.com>

move it to the beginning of the loop.

Cc: <stable at kernel.org>
Signed-off-by: Pavel Shilovsky <piastryyy at gmail.com>
Reviewed-by: Jeff Layton <jlayton at redhat.com>
---
 fs/cifs/cifsfs.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index fc7e57b..53e7d72 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -566,6 +566,12 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
 		struct inode *dir = dentry->d_inode;
 		struct dentry *child;
 
+		if (!dir) {
+			dput(dentry);
+			dentry = ERR_PTR(-ENOENT);
+			break;
+		}
+
 		/* skip separators */
 		while (*s == sep)
 			s++;
@@ -581,10 +587,6 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
 		mutex_unlock(&dir->i_mutex);
 		dput(dentry);
 		dentry = child;
-		if (!dentry->d_inode) {
-			dput(dentry);
-			dentry = ERR_PTR(-ENOENT);
-		}
 	} while (!IS_ERR(dentry));
 	_FreeXid(xid);
 	kfree(full_path);
-- 
1.7.6



More information about the kernel mailing list