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/hugetlbfs | |
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/hugetlbfs')
-rw-r--r-- | fs/hugetlbfs/inode.c | 12 |
1 files changed, 5 insertions, 7 deletions
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) |