From b10a4a9f7695335bd2bb19bffdda7fbefbc6581f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 9 Jul 2018 02:29:58 -0400 Subject: create_pipe_files(): use fput() if allocation of the second file fails ... just use put_pipe_info() to get the pipe->files down to 1 and let fput()-called pipe_release() do freeing. Acked-by: Linus Torvalds Signed-off-by: Al Viro --- fs/pipe.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'fs/pipe.c') diff --git a/fs/pipe.c b/fs/pipe.c index bb0840e234f3..9405e455f5b1 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -771,8 +771,9 @@ int create_pipe_files(struct file **res, int flags) res[0] = alloc_file(&path, FMODE_READ, &pipefifo_fops); if (IS_ERR(res[0])) { - err = PTR_ERR(res[0]); - goto err_file; + put_pipe_info(inode, inode->i_pipe); + fput(f); + return PTR_ERR(res[0]); } path_get(&path); @@ -781,8 +782,6 @@ int create_pipe_files(struct file **res, int flags) res[1] = f; return 0; -err_file: - put_filp(f); err_dentry: free_pipe_info(inode->i_pipe); path_put(&path); -- cgit From c9c554f21490bbc96cc554f80024d27d09670480 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 11 Jul 2018 14:19:04 -0400 Subject: alloc_file(): switch to passing O_... flags instead of FMODE_... mode ... so that it could set both ->f_flags and ->f_mode, without callers having to set ->f_flags manually. Signed-off-by: Al Viro --- fs/pipe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'fs/pipe.c') diff --git a/fs/pipe.c b/fs/pipe.c index 9405e455f5b1..1909422e5a78 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -760,16 +760,17 @@ int create_pipe_files(struct file **res, int flags) d_instantiate(path.dentry, inode); - f = alloc_file(&path, FMODE_WRITE, &pipefifo_fops); + f = alloc_file(&path, O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)), + &pipefifo_fops); if (IS_ERR(f)) { err = PTR_ERR(f); goto err_dentry; } - f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); f->private_data = inode->i_pipe; - res[0] = alloc_file(&path, FMODE_READ, &pipefifo_fops); + res[0] = alloc_file(&path, O_RDONLY | (flags & O_NONBLOCK), + &pipefifo_fops); if (IS_ERR(res[0])) { put_pipe_info(inode, inode->i_pipe); fput(f); @@ -778,7 +779,6 @@ int create_pipe_files(struct file **res, int flags) path_get(&path); res[0]->private_data = inode->i_pipe; - res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK); res[1] = f; return 0; -- cgit From 152b6372c90630ef6787334e84cdddbcf8beb241 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 9 Jun 2018 10:05:18 -0400 Subject: create_pipe_files(): switch the first allocation to alloc_file_pseudo() Acked-by: Linus Torvalds Signed-off-by: Al Viro --- fs/pipe.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'fs/pipe.c') diff --git a/fs/pipe.c b/fs/pipe.c index 1909422e5a78..9701bd3458d1 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -744,32 +744,24 @@ fail_inode: int create_pipe_files(struct file **res, int flags) { - int err; struct inode *inode = get_pipe_inode(); struct file *f; - struct path path; if (!inode) return -ENFILE; - err = -ENOMEM; - path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &empty_name); - if (!path.dentry) - goto err_inode; - path.mnt = mntget(pipe_mnt); - - d_instantiate(path.dentry, inode); - - f = alloc_file(&path, O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)), - &pipefifo_fops); + f = alloc_file_pseudo(inode, pipe_mnt, "", + O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)), + &pipefifo_fops); if (IS_ERR(f)) { - err = PTR_ERR(f); - goto err_dentry; + free_pipe_info(inode->i_pipe); + iput(inode); + return PTR_ERR(f); } f->private_data = inode->i_pipe; - res[0] = alloc_file(&path, O_RDONLY | (flags & O_NONBLOCK), + res[0] = alloc_file(&f->f_path, O_RDONLY | (flags & O_NONBLOCK), &pipefifo_fops); if (IS_ERR(res[0])) { put_pipe_info(inode, inode->i_pipe); @@ -777,20 +769,10 @@ int create_pipe_files(struct file **res, int flags) return PTR_ERR(res[0]); } - path_get(&path); + path_get(&f->f_path); res[0]->private_data = inode->i_pipe; res[1] = f; return 0; - -err_dentry: - free_pipe_info(inode->i_pipe); - path_put(&path); - return err; - -err_inode: - free_pipe_info(inode->i_pipe); - iput(inode); - return err; } static int __do_pipe_flags(int *fd, struct file **files, int flags) -- cgit From 183266f26f45a47958afb5c9aa1b3d4651e2eb8c Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 17 Jun 2018 14:15:10 -0400 Subject: new helper: alloc_file_clone() alloc_file_clone(old_file, mode, ops): create a new struct file with ->f_path equal to that of old_file. pipe converted. Acked-by: Linus Torvalds Signed-off-by: Al Viro --- fs/pipe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'fs/pipe.c') diff --git a/fs/pipe.c b/fs/pipe.c index 9701bd3458d1..5f50070774bc 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -761,15 +761,13 @@ int create_pipe_files(struct file **res, int flags) f->private_data = inode->i_pipe; - res[0] = alloc_file(&f->f_path, O_RDONLY | (flags & O_NONBLOCK), - &pipefifo_fops); + res[0] = alloc_file_clone(f, O_RDONLY | (flags & O_NONBLOCK), + &pipefifo_fops); if (IS_ERR(res[0])) { put_pipe_info(inode, inode->i_pipe); fput(f); return PTR_ERR(res[0]); } - - path_get(&f->f_path); res[0]->private_data = inode->i_pipe; res[1] = f; return 0; -- cgit