Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 95814
b: refs/heads/master
c: 5c598b3
h: refs/heads/master
v: v3
  • Loading branch information
Al Viro committed May 1, 2008
1 parent fd678c9 commit 75a3d21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2030a42cecd4dd1985a2ab03e25f3cd6106a5ca8
refs/heads/master: 5c598b3428c372a1209597cee99a70da20625876
22 changes: 20 additions & 2 deletions trunk/fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,16 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
nr /= (1024 / sizeof(struct file *));
nr = roundup_pow_of_two(nr + 1);
nr *= (1024 / sizeof(struct file *));
if (nr > sysctl_nr_open)
nr = sysctl_nr_open;
/*
* Note that this can drive nr *below* what we had passed if sysctl_nr_open
* had been set lower between the check in expand_files() and here. Deal
* with that in caller, it's cheaper that way.
*
* We make sure that nr remains a multiple of BITS_PER_LONG - otherwise
* bitmaps handling below becomes unpleasant, to put it mildly...
*/
if (unlikely(nr > sysctl_nr_open))
nr = ((sysctl_nr_open - 1) | (BITS_PER_LONG - 1)) + 1;

fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL);
if (!fdt)
Expand Down Expand Up @@ -199,6 +207,16 @@ static int expand_fdtable(struct files_struct *files, int nr)
spin_lock(&files->file_lock);
if (!new_fdt)
return -ENOMEM;
/*
* extremely unlikely race - sysctl_nr_open decreased between the check in
* caller and alloc_fdtable(). Cheaper to catch it here...
*/
if (unlikely(new_fdt->max_fds <= nr)) {
free_fdarr(new_fdt);
free_fdset(new_fdt);
kfree(new_fdt);
return -EMFILE;
}
/*
* Check again since another task may have expanded the fd table while
* we dropped the lock
Expand Down

0 comments on commit 75a3d21

Please sign in to comment.