diff options
Diffstat (limited to 'fs/file.c')
-rw-r--r-- | fs/file.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -240,13 +240,9 @@ static struct fdtable *alloc_fdtable(int nr) | |||
240 | if (!fdt) | 240 | if (!fdt) |
241 | goto out; | 241 | goto out; |
242 | 242 | ||
243 | nfds = 8 * L1_CACHE_BYTES; | 243 | nfds = max_t(int, 8 * L1_CACHE_BYTES, roundup_pow_of_two(nr + 1)); |
244 | /* Expand to the max in easy steps */ | 244 | if (nfds > NR_OPEN) |
245 | while (nfds <= nr) { | 245 | nfds = NR_OPEN; |
246 | nfds = nfds * 2; | ||
247 | if (nfds > NR_OPEN) | ||
248 | nfds = NR_OPEN; | ||
249 | } | ||
250 | 246 | ||
251 | new_openset = alloc_fdset(nfds); | 247 | new_openset = alloc_fdset(nfds); |
252 | new_execset = alloc_fdset(nfds); | 248 | new_execset = alloc_fdset(nfds); |
@@ -277,11 +273,13 @@ static struct fdtable *alloc_fdtable(int nr) | |||
277 | } while (nfds <= nr); | 273 | } while (nfds <= nr); |
278 | new_fds = alloc_fd_array(nfds); | 274 | new_fds = alloc_fd_array(nfds); |
279 | if (!new_fds) | 275 | if (!new_fds) |
280 | goto out; | 276 | goto out2; |
281 | fdt->fd = new_fds; | 277 | fdt->fd = new_fds; |
282 | fdt->max_fds = nfds; | 278 | fdt->max_fds = nfds; |
283 | fdt->free_files = NULL; | 279 | fdt->free_files = NULL; |
284 | return fdt; | 280 | return fdt; |
281 | out2: | ||
282 | nfds = fdt->max_fdset; | ||
285 | out: | 283 | out: |
286 | if (new_openset) | 284 | if (new_openset) |
287 | free_fdset(new_openset, nfds); | 285 | free_fdset(new_openset, nfds); |