--- linux-2.3.39-pre2.old/fs/select.c Tue Aug 31 13:30:48 1999 +++ linux-2.3.39-pre2/fs/select.c Mon Jan 10 02:19:21 2000 @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -375,7 +376,7 @@ { int i, fdcount, err, size; struct pollfd * fds, *fds1; - poll_table *wait_table = NULL, *wait = NULL; + poll_table *wait = NULL; lock_kernel(); /* Do a sanity check on nfds ... */ @@ -384,7 +385,7 @@ goto out; if (timeout) { - /* Carefula about overflow in the intermediate values */ + /* Careful about overflow in the intermediate values */ if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ) timeout = (unsigned long)(timeout*HZ+999)/1000+1; else /* Negative or overflow */ @@ -393,19 +394,25 @@ err = -ENOMEM; if (timeout) { - wait_table = (poll_table *) __get_free_page(GFP_KERNEL); - if (!wait_table) + wait = (poll_table *)__get_free_page(GFP_KERNEL); + if (!wait) goto out; - wait_table->nr = 0; - wait_table->entry = (struct poll_table_entry *)(wait_table + 1); - wait_table->next = NULL; - wait = wait_table; + wait->nr = 0; + wait->entry = (struct poll_table_entry *)(wait + 1); + wait->next = NULL; } size = nfds * sizeof(struct pollfd); - fds = (struct pollfd *) kmalloc(size, GFP_KERNEL); + + if (size < PAGE_SIZE) + fds = (struct pollfd *)kmalloc(size, GFP_KERNEL); + else if (size == PAGE_SIZE) + fds = (struct pollfd *)__get_free_page(GFP_KERNEL); + else + fds = (struct pollfd *)vmalloc(size); + if (!fds) - goto out; + goto out_nomem; err = -EFAULT; if (copy_from_user(fds, ufds, size)) @@ -415,19 +422,23 @@ /* OK, now copy the revents fields back to user space. */ fds1 = fds; - for(i=0; i < (int)nfds; i++, ufds++, fds1++) { + for (i = 0; i < (int)nfds; i++, ufds++, fds1++) __put_user(fds1->revents, &ufds->revents); - } err = fdcount; if (!fdcount && signal_pending(current)) err = -EINTR; out_fds: - kfree(fds); + if (size < PAGE_SIZE) + kfree(fds); + else if (size == PAGE_SIZE) + free_page((unsigned long)fds); + else + vfree(fds); +out_nomem: + free_wait(wait); out: - if (wait) - free_wait(wait_table); unlock_kernel(); return err; }