Skip to content

Commit 322794d

Browse files
lxbszidryomov
authored andcommitted
ceph: fix inode reference leakage in ceph_get_snapdir()
The ceph_get_inode() will search for or insert a new inode into the hash for the given vino, and return a reference to it. If new is non-NULL, its reference is consumed. We should release the reference when in error handing cases. Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent ad5255c commit 322794d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

fs/ceph/inode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ struct inode *ceph_get_snapdir(struct inode *parent)
8787
if (!S_ISDIR(parent->i_mode)) {
8888
pr_warn_once("bad snapdir parent type (mode=0%o)\n",
8989
parent->i_mode);
90-
return ERR_PTR(-ENOTDIR);
90+
goto err;
9191
}
9292

9393
if (!(inode->i_state & I_NEW) && !S_ISDIR(inode->i_mode)) {
9494
pr_warn_once("bad snapdir inode type (mode=0%o)\n",
9595
inode->i_mode);
96-
return ERR_PTR(-ENOTDIR);
96+
goto err;
9797
}
9898

9999
inode->i_mode = parent->i_mode;
@@ -113,6 +113,12 @@ struct inode *ceph_get_snapdir(struct inode *parent)
113113
}
114114

115115
return inode;
116+
err:
117+
if ((inode->i_state & I_NEW))
118+
discard_new_inode(inode);
119+
else
120+
iput(inode);
121+
return ERR_PTR(-ENOTDIR);
116122
}
117123

118124
const struct inode_operations ceph_file_iops = {

0 commit comments

Comments
 (0)