Skip to content

Commit 6a8126f

Browse files
author
Al Viro
committed
expand_files(): simplify calling conventions
All callers treat 0 and 1 returned by expand_files() in the same way now since the call in alloc_fd() had been made conditional. Just make it return 0 on success and be done with it... Signed-off-by: Al Viro <[email protected]>
1 parent b8ea429 commit 6a8126f

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

fs/file.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static struct fdtable *alloc_fdtable(unsigned int slots_wanted)
162162
* Expand the file descriptor table.
163163
* This function will allocate a new fdtable and both fd array and fdset, of
164164
* the given size.
165-
* Return <0 error code on error; 1 on successful completion.
165+
* Return <0 error code on error; 0 on successful completion.
166166
* The files->file_lock should be held on entry, and will be held on exit.
167167
*/
168168
static int expand_fdtable(struct files_struct *files, unsigned int nr)
@@ -191,50 +191,48 @@ static int expand_fdtable(struct files_struct *files, unsigned int nr)
191191
call_rcu(&cur_fdt->rcu, free_fdtable_rcu);
192192
/* coupled with smp_rmb() in fd_install() */
193193
smp_wmb();
194-
return 1;
194+
return 0;
195195
}
196196

197197
/*
198198
* Expand files.
199199
* This function will expand the file structures, if the requested size exceeds
200200
* the current capacity and there is room for expansion.
201-
* Return <0 error code on error; 0 when nothing done; 1 when files were
202-
* expanded and execution may have blocked.
201+
* Return <0 error code on error; 0 on success.
203202
* The files->file_lock should be held on entry, and will be held on exit.
204203
*/
205204
static int expand_files(struct files_struct *files, unsigned int nr)
206205
__releases(files->file_lock)
207206
__acquires(files->file_lock)
208207
{
209208
struct fdtable *fdt;
210-
int expanded = 0;
209+
int error;
211210

212211
repeat:
213212
fdt = files_fdtable(files);
214213

215214
/* Do we need to expand? */
216215
if (nr < fdt->max_fds)
217-
return expanded;
216+
return 0;
218217

219218
/* Can we expand? */
220219
if (nr >= sysctl_nr_open)
221220
return -EMFILE;
222221

223222
if (unlikely(files->resize_in_progress)) {
224223
spin_unlock(&files->file_lock);
225-
expanded = 1;
226224
wait_event(files->resize_wait, !files->resize_in_progress);
227225
spin_lock(&files->file_lock);
228226
goto repeat;
229227
}
230228

231229
/* All good, so we try */
232230
files->resize_in_progress = true;
233-
expanded = expand_fdtable(files, nr);
231+
error = expand_fdtable(files, nr);
234232
files->resize_in_progress = false;
235233

236234
wake_up_all(&files->resize_wait);
237-
return expanded;
235+
return error;
238236
}
239237

240238
static inline void __set_close_on_exec(unsigned int fd, struct fdtable *fdt,
@@ -507,12 +505,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
507505
if (error < 0)
508506
goto out;
509507

510-
/*
511-
* If we needed to expand the fs array we
512-
* might have blocked - try again.
513-
*/
514-
if (error)
515-
goto repeat;
508+
goto repeat;
516509
}
517510

518511
if (start <= files->next_fd)

0 commit comments

Comments
 (0)