aboutsummaryrefslogtreecommitdiffstats
path: root/fs/file_table.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-02-14 20:41:04 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2013-02-22 23:31:32 -0500
commit1afc99beaf0fca3767d9b67789a7ae91c4f7a9c9 (patch)
tree9aba84bc2d8e4873859bd81ddf1002fe0e3f9376 /fs/file_table.c
parent496ad9aa8ef448058e36ca7a787c61f2e63f0f54 (diff)
propagate error from get_empty_filp() to its callers
Based on parts from Anatol's patch (the rest is the next commit). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/file_table.c')
-rw-r--r--fs/file_table.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 0f607ce89acc..cd76d4fdf4a4 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -94,8 +94,8 @@ int proc_nr_files(ctl_table *table, int write,
94#endif 94#endif
95 95
96/* Find an unused file structure and return a pointer to it. 96/* Find an unused file structure and return a pointer to it.
97 * Returns NULL, if there are no more free file structures or 97 * Returns an error pointer if some error happend e.g. we over file
98 * we run out of memory. 98 * structures limit, run out of memory or operation is not permitted.
99 * 99 *
100 * Be very careful using this. You are responsible for 100 * Be very careful using this. You are responsible for
101 * getting write access to any mount that you might assign 101 * getting write access to any mount that you might assign
@@ -107,7 +107,8 @@ struct file *get_empty_filp(void)
107{ 107{
108 const struct cred *cred = current_cred(); 108 const struct cred *cred = current_cred();
109 static long old_max; 109 static long old_max;
110 struct file * f; 110 struct file *f;
111 int error;
111 112
112 /* 113 /*
113 * Privileged users can go above max_files 114 * Privileged users can go above max_files
@@ -122,13 +123,16 @@ struct file *get_empty_filp(void)
122 } 123 }
123 124
124 f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL); 125 f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL);
125 if (f == NULL) 126 if (unlikely(!f))
126 goto fail; 127 return ERR_PTR(-ENOMEM);
127 128
128 percpu_counter_inc(&nr_files); 129 percpu_counter_inc(&nr_files);
129 f->f_cred = get_cred(cred); 130 f->f_cred = get_cred(cred);
130 if (security_file_alloc(f)) 131 error = security_file_alloc(f);
131 goto fail_sec; 132 if (unlikely(error)) {
133 file_free(f);
134 return ERR_PTR(error);
135 }
132 136
133 INIT_LIST_HEAD(&f->f_u.fu_list); 137 INIT_LIST_HEAD(&f->f_u.fu_list);
134 atomic_long_set(&f->f_count, 1); 138 atomic_long_set(&f->f_count, 1);
@@ -144,12 +148,7 @@ over:
144 pr_info("VFS: file-max limit %lu reached\n", get_max_files()); 148 pr_info("VFS: file-max limit %lu reached\n", get_max_files());
145 old_max = get_nr_files(); 149 old_max = get_nr_files();
146 } 150 }
147 goto fail; 151 return ERR_PTR(-ENFILE);
148
149fail_sec:
150 file_free(f);
151fail:
152 return NULL;
153} 152}
154 153
155/** 154/**
@@ -173,7 +172,7 @@ struct file *alloc_file(struct path *path, fmode_t mode,
173 struct file *file; 172 struct file *file;
174 173
175 file = get_empty_filp(); 174 file = get_empty_filp();
176 if (!file) 175 if (IS_ERR(file))
177 return NULL; 176 return NULL;
178 177
179 file->f_path = *path; 178 file->f_path = *path;