diff options
author | Anatol Pomozov <anatol.pomozov@gmail.com> | 2012-09-12 23:11:55 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-02-22 23:31:32 -0500 |
commit | 39b652527457452f09b35044fb4f8b3b0eabafdf (patch) | |
tree | acd8fda1d4e37c58c68fe0cfb9288d5d06e14441 /fs | |
parent | 1afc99beaf0fca3767d9b67789a7ae91c4f7a9c9 (diff) |
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 <anatol.pomozov@gmail.com>
Reviewed-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/anon_inodes.c | 8 | ||||
-rw-r--r-- | fs/file_table.c | 2 | ||||
-rw-r--r-- | fs/hugetlbfs/inode.c | 12 | ||||
-rw-r--r-- | fs/pipe.c | 4 |
4 files changed, 11 insertions, 15 deletions
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 28d39fb84ae3..a14eb0c1cd8c 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c | |||
@@ -131,7 +131,6 @@ struct file *anon_inode_getfile(const char *name, | |||
131 | struct qstr this; | 131 | struct qstr this; |
132 | struct path path; | 132 | struct path path; |
133 | struct file *file; | 133 | struct file *file; |
134 | int error; | ||
135 | 134 | ||
136 | if (IS_ERR(anon_inode_inode)) | 135 | if (IS_ERR(anon_inode_inode)) |
137 | return ERR_PTR(-ENODEV); | 136 | return ERR_PTR(-ENODEV); |
@@ -143,7 +142,7 @@ struct file *anon_inode_getfile(const char *name, | |||
143 | * Link the inode to a directory entry by creating a unique name | 142 | * Link the inode to a directory entry by creating a unique name |
144 | * using the inode sequence number. | 143 | * using the inode sequence number. |
145 | */ | 144 | */ |
146 | error = -ENOMEM; | 145 | file = ERR_PTR(-ENOMEM); |
147 | this.name = name; | 146 | this.name = name; |
148 | this.len = strlen(name); | 147 | this.len = strlen(name); |
149 | this.hash = 0; | 148 | this.hash = 0; |
@@ -160,9 +159,8 @@ struct file *anon_inode_getfile(const char *name, | |||
160 | 159 | ||
161 | d_instantiate(path.dentry, anon_inode_inode); | 160 | d_instantiate(path.dentry, anon_inode_inode); |
162 | 161 | ||
163 | error = -ENFILE; | ||
164 | file = alloc_file(&path, OPEN_FMODE(flags), fops); | 162 | file = alloc_file(&path, OPEN_FMODE(flags), fops); |
165 | if (!file) | 163 | if (IS_ERR(file)) |
166 | goto err_dput; | 164 | goto err_dput; |
167 | file->f_mapping = anon_inode_inode->i_mapping; | 165 | file->f_mapping = anon_inode_inode->i_mapping; |
168 | 166 | ||
@@ -177,7 +175,7 @@ err_dput: | |||
177 | path_put(&path); | 175 | path_put(&path); |
178 | err_module: | 176 | err_module: |
179 | module_put(fops->owner); | 177 | module_put(fops->owner); |
180 | return ERR_PTR(error); | 178 | return file; |
181 | } | 179 | } |
182 | EXPORT_SYMBOL_GPL(anon_inode_getfile); | 180 | EXPORT_SYMBOL_GPL(anon_inode_getfile); |
183 | 181 | ||
diff --git a/fs/file_table.c b/fs/file_table.c index cd76d4fdf4a4..aa07d3684a2e 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -173,7 +173,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, | |||
173 | 173 | ||
174 | file = get_empty_filp(); | 174 | file = get_empty_filp(); |
175 | if (IS_ERR(file)) | 175 | if (IS_ERR(file)) |
176 | return NULL; | 176 | return file; |
177 | 177 | ||
178 | file->f_path = *path; | 178 | file->f_path = *path; |
179 | file->f_mapping = path->dentry->d_inode->i_mapping; | 179 | file->f_mapping = path->dentry->d_inode->i_mapping; |
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index edb42ea60c76..99fe7ef2f09b 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c | |||
@@ -923,8 +923,7 @@ struct file *hugetlb_file_setup(const char *name, unsigned long addr, | |||
923 | struct user_struct **user, | 923 | struct user_struct **user, |
924 | int creat_flags, int page_size_log) | 924 | int creat_flags, int page_size_log) |
925 | { | 925 | { |
926 | int error = -ENOMEM; | 926 | struct file *file = ERR_PTR(-ENOMEM); |
927 | struct file *file; | ||
928 | struct inode *inode; | 927 | struct inode *inode; |
929 | struct path path; | 928 | struct path path; |
930 | struct dentry *root; | 929 | struct dentry *root; |
@@ -964,7 +963,7 @@ struct file *hugetlb_file_setup(const char *name, unsigned long addr, | |||
964 | goto out_shm_unlock; | 963 | goto out_shm_unlock; |
965 | 964 | ||
966 | path.mnt = mntget(hugetlbfs_vfsmount[hstate_idx]); | 965 | path.mnt = mntget(hugetlbfs_vfsmount[hstate_idx]); |
967 | error = -ENOSPC; | 966 | file = ERR_PTR(-ENOSPC); |
968 | inode = hugetlbfs_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0); | 967 | inode = hugetlbfs_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0); |
969 | if (!inode) | 968 | if (!inode) |
970 | goto out_dentry; | 969 | goto out_dentry; |
@@ -973,7 +972,7 @@ struct file *hugetlb_file_setup(const char *name, unsigned long addr, | |||
973 | size += addr & ~huge_page_mask(hstate); | 972 | size += addr & ~huge_page_mask(hstate); |
974 | num_pages = ALIGN(size, huge_page_size(hstate)) >> | 973 | num_pages = ALIGN(size, huge_page_size(hstate)) >> |
975 | huge_page_shift(hstate); | 974 | huge_page_shift(hstate); |
976 | error = -ENOMEM; | 975 | file = ERR_PTR(-ENOMEM); |
977 | if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag)) | 976 | if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag)) |
978 | goto out_inode; | 977 | goto out_inode; |
979 | 978 | ||
@@ -981,10 +980,9 @@ struct file *hugetlb_file_setup(const char *name, unsigned long addr, | |||
981 | inode->i_size = size; | 980 | inode->i_size = size; |
982 | clear_nlink(inode); | 981 | clear_nlink(inode); |
983 | 982 | ||
984 | error = -ENFILE; | ||
985 | file = alloc_file(&path, FMODE_WRITE | FMODE_READ, | 983 | file = alloc_file(&path, FMODE_WRITE | FMODE_READ, |
986 | &hugetlbfs_file_operations); | 984 | &hugetlbfs_file_operations); |
987 | if (!file) | 985 | if (IS_ERR(file)) |
988 | goto out_dentry; /* inode is already attached */ | 986 | goto out_dentry; /* inode is already attached */ |
989 | 987 | ||
990 | return file; | 988 | return file; |
@@ -998,7 +996,7 @@ out_shm_unlock: | |||
998 | user_shm_unlock(size, *user); | 996 | user_shm_unlock(size, *user); |
999 | *user = NULL; | 997 | *user = NULL; |
1000 | } | 998 | } |
1001 | return ERR_PTR(error); | 999 | return file; |
1002 | } | 1000 | } |
1003 | 1001 | ||
1004 | static int __init init_hugetlbfs_fs(void) | 1002 | static int __init init_hugetlbfs_fs(void) |
@@ -1037,13 +1037,13 @@ int create_pipe_files(struct file **res, int flags) | |||
1037 | 1037 | ||
1038 | err = -ENFILE; | 1038 | err = -ENFILE; |
1039 | f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops); | 1039 | f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops); |
1040 | if (!f) | 1040 | if (IS_ERR(f)) |
1041 | goto err_dentry; | 1041 | goto err_dentry; |
1042 | 1042 | ||
1043 | f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); | 1043 | f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); |
1044 | 1044 | ||
1045 | res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops); | 1045 | res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops); |
1046 | if (!res[0]) | 1046 | if (IS_ERR(res[0])) |
1047 | goto err_file; | 1047 | goto err_file; |
1048 | 1048 | ||
1049 | path_get(&path); | 1049 | path_get(&path); |