From 92c3c254d7dafcb16d2948c37518f09c5883be05 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Mon, 10 Apr 2006 22:54:08 -0700 Subject: [PATCH] --- yaml --- r: 25508 b: refs/heads/master c: b04eb6aa08ecc3e24df2f78ebc486011ebd74feb h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/select.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/[refs] b/[refs] index a4c9c128ffd2..53358f61de83 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a9cdf410ca8f59b52bc7061a6751050010c7cc5b +refs/heads/master: b04eb6aa08ecc3e24df2f78ebc486011ebd74feb diff --git a/trunk/fs/select.c b/trunk/fs/select.c index fce0fd1bb1d1..a8109baa5e46 100644 --- a/trunk/fs/select.c +++ b/trunk/fs/select.c @@ -311,7 +311,8 @@ static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, { fd_set_bits fds; void *bits; - int ret, size, max_fdset; + int ret, max_fdset; + unsigned int size; struct fdtable *fdt; /* Allocate small arguments on the stack to save memory and be faster */ long stack_fds[SELECT_STACK_ALLOC/sizeof(long)]; @@ -333,14 +334,15 @@ static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, * since we used fdset we need to allocate memory in units of * long-words. */ - ret = -ENOMEM; size = FDS_BYTES(n); - if (6*size < SELECT_STACK_ALLOC) - bits = stack_fds; - else + bits = stack_fds; + if (size > sizeof(stack_fds) / 6) { + /* Not enough space in on-stack array; must use kmalloc */ + ret = -ENOMEM; bits = kmalloc(6 * size, GFP_KERNEL); - if (!bits) - goto out_nofds; + if (!bits) + goto out_nofds; + } fds.in = bits; fds.out = bits + size; fds.ex = bits + 2*size;