ARM: tegra: power: Set minimum LP2 target residency
[linux-3.10.git] / fs / select.c
index ecfd0b1..6b14dc7 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/syscalls.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/poll.h>
 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
@@ -26,6 +26,8 @@
 #include <linux/fs.h>
 #include <linux/rcupdate.h>
 #include <linux/hrtimer.h>
+#include <linux/sched/rt.h>
+#include <linux/freezer.h>
 
 #include <asm/uaccess.h>
 
@@ -220,8 +222,7 @@ static void __pollwait(struct file *filp, wait_queue_head_t *wait_address,
        struct poll_table_entry *entry = poll_get_entry(pwq);
        if (!entry)
                return;
-       get_file(filp);
-       entry->filp = filp;
+       entry->filp = get_file(filp);
        entry->wait_address = wait_address;
        entry->key = p->_key;
        init_waitqueue_func_entry(&entry->wait, pollwake);
@@ -236,7 +237,8 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
 
        set_current_state(state);
        if (!pwq->triggered)
-               rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
+               rc = freezable_schedule_hrtimeout_range(expires, slack,
+                                                       HRTIMER_MODE_ABS);
        __set_current_state(TASK_RUNNING);
 
        /*
@@ -345,10 +347,10 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
        struct fdtable *fdt;
 
        /* handle last in-complete long-word first */
-       set = ~(~0UL << (n & (__NFDBITS-1)));
-       n /= __NFDBITS;
+       set = ~(~0UL << (n & (BITS_PER_LONG-1)));
+       n /= BITS_PER_LONG;
        fdt = files_fdtable(current->files);
-       open_fds = fdt->open_fds->fds_bits+n;
+       open_fds = fdt->open_fds + n;
        max = 0;
        if (set) {
                set &= BITS(fds, n);
@@ -373,7 +375,7 @@ get_max:
                        max++;
                        set >>= 1;
                } while (set);
-               max += n * __NFDBITS;
+               max += n * BITS_PER_LONG;
        }
 
        return max;
@@ -429,31 +431,30 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
                for (i = 0; i < n; ++rinp, ++routp, ++rexp) {
                        unsigned long in, out, ex, all_bits, bit = 1, mask, j;
                        unsigned long res_in = 0, res_out = 0, res_ex = 0;
-                       const struct file_operations *f_op = NULL;
-                       struct file *file = NULL;
 
                        in = *inp++; out = *outp++; ex = *exp++;
                        all_bits = in | out | ex;
                        if (all_bits == 0) {
-                               i += __NFDBITS;
+                               i += BITS_PER_LONG;
                                continue;
                        }
 
-                       for (j = 0; j < __NFDBITS; ++j, ++i, bit <<= 1) {
-                               int fput_needed;
+                       for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) {
+                               struct fd f;
                                if (i >= n)
                                        break;
                                if (!(bit & all_bits))
                                        continue;
-                               file = fget_light(i, &fput_needed);
-                               if (file) {
-                                       f_op = file->f_op;
+                               f = fdget(i);
+                               if (f.file) {
+                                       const struct file_operations *f_op;
+                                       f_op = f.file->f_op;
                                        mask = DEFAULT_POLLMASK;
                                        if (f_op && f_op->poll) {
                                                wait_key_set(wait, in, out, bit);
-                                               mask = (*f_op->poll)(file, wait);
+                                               mask = (*f_op->poll)(f.file, wait);
                                        }
-                                       fput_light(file, fput_needed);
+                                       fdput(f);
                                        if ((mask & POLLIN_SET) && (in & bit)) {
                                                res_in |= bit;
                                                retval++;
@@ -614,7 +615,6 @@ SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
        return ret;
 }
 
-#ifdef HAVE_SET_RESTORE_SIGMASK
 static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
                       fd_set __user *exp, struct timespec __user *tsp,
                       const sigset_t __user *sigmask, size_t sigsetsize)
@@ -686,7 +686,6 @@ SYSCALL_DEFINE6(pselect6, int, n, fd_set __user *, inp, fd_set __user *, outp,
 
        return do_pselect(n, inp, outp, exp, tsp, up, sigsetsize);
 }
-#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 #ifdef __ARCH_WANT_SYS_OLD_SELECT
 struct sel_arg_struct {
@@ -728,20 +727,17 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait)
        mask = 0;
        fd = pollfd->fd;
        if (fd >= 0) {
-               int fput_needed;
-               struct file * file;
-
-               file = fget_light(fd, &fput_needed);
+               struct fd f = fdget(fd);
                mask = POLLNVAL;
-               if (file != NULL) {
+               if (f.file) {
                        mask = DEFAULT_POLLMASK;
-                       if (file->f_op && file->f_op->poll) {
+                       if (f.file->f_op && f.file->f_op->poll) {
                                pwait->_key = pollfd->events|POLLERR|POLLHUP;
-                               mask = file->f_op->poll(file, pwait);
+                               mask = f.file->f_op->poll(f.file, pwait);
                        }
                        /* Mask out unneeded events. */
                        mask &= pollfd->events | POLLERR | POLLHUP;
-                       fput_light(file, fput_needed);
+                       fdput(f);
                }
        }
        pollfd->revents = mask;
@@ -941,7 +937,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
        return ret;
 }
 
-#ifdef HAVE_SET_RESTORE_SIGMASK
 SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
                struct timespec __user *, tsp, const sigset_t __user *, sigmask,
                size_t, sigsetsize)
@@ -992,4 +987,3 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
 
        return ret;
 }
-#endif /* HAVE_SET_RESTORE_SIGMASK */