revert android-tegra-2.6.36-honeycomb-mr1-9001adc to v2.6.36
[firefly-linux-kernel-4.4.55.git] / fs / eventpoll.c
index c6341501f30ce02d2d119fb3dbf16f71dce8259c..3817149919cb81fa298686f183f67e0c86fe1c50 100644 (file)
@@ -77,6 +77,9 @@
 /* Maximum number of nesting allowed inside epoll sets */
 #define EP_MAX_NESTS 4
 
+/* Maximum msec timeout value storeable in a long int */
+#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ)
+
 #define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))
 
 #define EP_UNACTIVE_PTR ((void *) -1L)
@@ -1113,22 +1116,18 @@ static int ep_send_events(struct eventpoll *ep,
 static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
                   int maxevents, long timeout)
 {
-       int res, eavail, timed_out = 0;
+       int res, eavail;
        unsigned long flags;
-       long slack;
+       long jtimeout;
        wait_queue_t wait;
-       struct timespec end_time;
-       ktime_t expires, *to = NULL;
-
-       if (timeout > 0) {
-               ktime_get_ts(&end_time);
-               timespec_add_ns(&end_time, (u64)timeout * NSEC_PER_MSEC);
-               slack = select_estimate_accuracy(&end_time);
-               to = &expires;
-               *to = timespec_to_ktime(end_time);
-       } else if (timeout == 0) {
-               timed_out = 1;
-       }
+
+       /*
+        * Calculate the timeout by checking for the "infinite" value (-1)
+        * and the overflow condition. The passed timeout is in milliseconds,
+        * that why (t * HZ) / 1000.
+        */
+       jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ?
+               MAX_SCHEDULE_TIMEOUT : (timeout * HZ + 999) / 1000;
 
 retry:
        spin_lock_irqsave(&ep->lock, flags);
@@ -1150,7 +1149,7 @@ retry:
                         * to TASK_INTERRUPTIBLE before doing the checks.
                         */
                        set_current_state(TASK_INTERRUPTIBLE);
-                       if (!list_empty(&ep->rdllist) || timed_out)
+                       if (!list_empty(&ep->rdllist) || !jtimeout)
                                break;
                        if (signal_pending(current)) {
                                res = -EINTR;
@@ -1158,9 +1157,7 @@ retry:
                        }
 
                        spin_unlock_irqrestore(&ep->lock, flags);
-                       if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
-                               timed_out = 1;
-
+                       jtimeout = schedule_timeout(jtimeout);
                        spin_lock_irqsave(&ep->lock, flags);
                }
                __remove_wait_queue(&ep->wq, &wait);
@@ -1178,7 +1175,7 @@ retry:
         * more luck.
         */
        if (!res && eavail &&
-           !(res = ep_send_events(ep, events, maxevents)) && !timed_out)
+           !(res = ep_send_events(ep, events, maxevents)) && jtimeout)
                goto retry;
 
        return res;