]> Pileus Git - ~andy/linux/blobdiff - fs/select.c
[PATCH] splice: redo page lookup if add_to_page_cache() returns -EEXIST
[~andy/linux] / fs / select.c
index fce0fd1bb1d1210feeda5fbb328c064c5ca007f9..a8109baa5e46429a894664eba4bfe1ce25f4b89b 100644 (file)
@@ -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;