From 39b652527457452f09b35044fb4f8b3b0eabafdf Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Wed, 12 Sep 2012 20:11:55 -0700 Subject: fs: Preserve error code in get_empty_filp(), part 2 Allocating a file structure in function get_empty_filp() might fail because of several reasons: - not enough memory for file structures - operation is not allowed - user is over its limit Currently the function returns NULL in all cases and we loose the exact reason of the error. All callers of get_empty_filp() assume that the function can fail with ENFILE only. Return error through pointer. Change all callers to preserve this error code. [AV: cleaned up a bit, carved the get_empty_filp() part out into a separate commit (things remaining here deal with alloc_file()), removed pipe(2) behaviour change] Signed-off-by: Anatol Pomozov Reviewed-by: "Theodore Ts'o" Signed-off-by: Al Viro --- net/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net/socket.c') diff --git a/net/socket.c b/net/socket.c index 2ca51c719ef9..f4a8c5a0b8d7 100644 --- a/net/socket.c +++ b/net/socket.c @@ -370,11 +370,11 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) file = alloc_file(&path, FMODE_READ | FMODE_WRITE, &socket_file_ops); - if (unlikely(!file)) { + if (unlikely(IS_ERR(file))) { /* drop dentry, keep inode */ ihold(path.dentry->d_inode); path_put(&path); - return ERR_PTR(-ENFILE); + return file; } sock->file = file; -- cgit v1.2.3 From 21d206819a6f111c77f0a9e920f5efca06dc65fd Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 23 Feb 2013 17:36:01 -0500 Subject: get_empty_filp()/alloc_file() leave both ->f_pos and ->f_version zero Signed-off-by: Al Viro --- fs/anon_inodes.c | 2 -- fs/open.c | 1 - net/socket.c | 1 - 3 files changed, 4 deletions(-) (limited to 'net/socket.c') diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index a14eb0c1cd8c..47a65df8c871 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -164,9 +164,7 @@ struct file *anon_inode_getfile(const char *name, goto err_dput; file->f_mapping = anon_inode_inode->i_mapping; - file->f_pos = 0; file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); - file->f_version = 0; file->private_data = priv; return file; diff --git a/fs/open.c b/fs/open.c index 97a237f67b72..62f907e3bc36 100644 --- a/fs/open.c +++ b/fs/open.c @@ -699,7 +699,6 @@ static int do_dentry_open(struct file *f, } f->f_mapping = inode->i_mapping; - f->f_pos = 0; file_sb_list_add(f, inode->i_sb); if (unlikely(f->f_mode & FMODE_PATH)) { diff --git a/net/socket.c b/net/socket.c index f4a8c5a0b8d7..b6ca6896dec6 100644 --- a/net/socket.c +++ b/net/socket.c @@ -379,7 +379,6 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) sock->file = file; file->f_flags = O_RDWR | (flags & O_NONBLOCK); - file->f_pos = 0; file->private_data = sock; return file; } -- cgit v1.2.3