Skip to contentSkip to conversation

ceph: check for null dentry in ceph_dir_set_complete()

PATCH In review Alex Elder 1 participant 1 message Dec 22, 2011 Ceph client

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/3 ceph: check for null dentry in ceph_dir_set_complete()

In ceph_dir_set_complete(), the return value of __d_find_any_alias() is blindly dereferenced. That function can return a null pointer, so the dereference needs to be protected by a check for that.

---
 fs/ceph/dir.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/ceph/dir.c +7 -5
Index: b/fs/ceph/dir.c
===================================================================
@@ -1115,12 +1115,14 @@ static struct dentry * __d_find_any_alia
 void ceph_dir_set_complete(struct inode *inode)
 {
 	struct dentry *dentry = __d_find_any_alias(inode);
-	struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
 	
-	if (dentry && ceph_dentry(dentry) &&
-	    ceph_test_mount_opt(fsc, USEDCACHE)) {
-		dout(" marking %p (%p) complete\n", inode, dentry);
-		set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
+	if (dentry && ceph_dentry(dentry)) {
+		struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
+
+		if (ceph_test_mount_opt(fsc, USEDCACHE)) {
+			dout(" marking %p (%p) complete\n", inode, dentry);
+			set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
+		}
 	}
 }