Skip to content

Commit 5ca1db4

Browse files
szmiswhiteho
authored andcommitted
GFS2: fix dentry leaks
We need to dput() the result of d_splice_alias(), unless it is passed to finish_no_open(). Edited by Steven Whitehouse in order to make it apply to the current GFS2 git tree, and taking account of a prerequisite patch which hasn't been applied. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com> Cc: stable@vger.kernel.org
1 parent 149ed7f commit 5ca1db4

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎fs/gfs2/inode.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,14 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
585585
d = d_splice_alias(inode, dentry);
586586
error = 0;
587587
if (file) {
588-
if (d == NULL)
589-
d = dentry;
590-
if (S_ISREG(inode->i_mode))
591-
error = finish_open(file, d, gfs2_open_common, opened);
592-
else
588+
if (S_ISREG(inode->i_mode)) {
589+
WARN_ON(d != NULL);
590+
error = finish_open(file, dentry, gfs2_open_common, opened);
591+
} else {
593592
error = finish_no_open(file, d);
593+
}
594+
} else {
595+
dput(d);
594596
}
595597
gfs2_glock_dq_uninit(ghs);
596598
return error;
@@ -777,8 +779,10 @@ static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry,
777779
error = finish_open(file, dentry, gfs2_open_common, opened);
778780

779781
gfs2_glock_dq_uninit(&gh);
780-
if (error)
782+
if (error) {
783+
dput(d);
781784
return ERR_PTR(error);
785+
}
782786
return d;
783787
}
784788

@@ -1159,14 +1163,16 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
11591163
d = __gfs2_lookup(dir, dentry, file, opened);
11601164
if (IS_ERR(d))
11611165
return PTR_ERR(d);
1162-
if (d == NULL)
1163-
d = dentry;
1164-
if (d->d_inode) {
1166+
if (d != NULL)
1167+
dentry = d;
1168+
if (dentry->d_inode) {
11651169
if (!(*opened & FILE_OPENED))
1166-
return finish_no_open(file, d);
1170+
return finish_no_open(file, dentry);
1171+
dput(d);
11671172
return 0;
11681173
}
11691174

1175+
BUG_ON(d != NULL);
11701176
if (!(flags & O_CREAT))
11711177
return -ENOENT;
11721178

0 commit comments

Comments
 (0)