int sig;
        struct timespec t;
        siginfo_t info;
-       long ret, timeout = 0;
+       long ret, timeout;
 
        if (sigsetsize != sizeof(sigset_t))
                return -EINVAL;
        sigdelsetmask(&s,sigmask(SIGKILL)|sigmask(SIGSTOP));
        signotset(&s);
 
+       timeout = MAX_SCHEDULE_TIMEOUT;
        if (uts) {
                if (get_compat_timespec (&t, uts))
                        return -EFAULT;
-               if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0
-                               || t.tv_sec < 0)
+               if (!timespec_valid(&t))
                        return -EINVAL;
+               timeout = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
        }
 
        spin_lock_irq(¤t->sighand->siglock);
        sig = dequeue_signal(current, &s, &info);
-       if (!sig) {
-               timeout = MAX_SCHEDULE_TIMEOUT;
-               if (uts)
-                       timeout = timespec_to_jiffies(&t)
-                               +(t.tv_sec || t.tv_nsec);
-               if (timeout) {
-                       current->real_blocked = current->blocked;
-                       sigandsets(¤t->blocked, ¤t->blocked, &s);
-
-                       recalc_sigpending();
-                       spin_unlock_irq(¤t->sighand->siglock);
-
-                       timeout = schedule_timeout_interruptible(timeout);
-
-                       spin_lock_irq(¤t->sighand->siglock);
-                       sig = dequeue_signal(current, &s, &info);
-                       current->blocked = current->real_blocked;
-                       siginitset(¤t->real_blocked, 0);
-                       recalc_sigpending();
-               }
+       if (!sig && timeout) {
+               current->real_blocked = current->blocked;
+               sigandsets(¤t->blocked, ¤t->blocked, &s);
+               recalc_sigpending();
+               spin_unlock_irq(¤t->sighand->siglock);
+
+               timeout = schedule_timeout_interruptible(timeout);
+
+               spin_lock_irq(¤t->sighand->siglock);
+               sig = dequeue_signal(current, &s, &info);
+               current->blocked = current->real_blocked;
+               siginitset(¤t->real_blocked, 0);
+               recalc_sigpending();
        }
        spin_unlock_irq(¤t->sighand->siglock);
 
                        if (copy_siginfo_to_user32(uinfo, &info))
                                ret = -EFAULT;
                }
-       }else {
+       } else {
                ret = timeout?-EINTR:-EAGAIN;
        }
        return ret;
 
        sigset_t these;
        struct timespec ts;
        siginfo_t info;
-       long timeout = 0;
+       long timeout;
 
        /* XXX: Don't preclude handling different sized sigset_t's.  */
        if (sigsetsize != sizeof(sigset_t))
        sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
        signotset(&these);
 
+       timeout = MAX_SCHEDULE_TIMEOUT;
        if (uts) {
                if (copy_from_user(&ts, uts, sizeof(ts)))
                        return -EFAULT;
-               if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
-                   || ts.tv_sec < 0)
+               if (!timespec_valid(&ts))
                        return -EINVAL;
+               timeout = timespec_to_jiffies(&ts) + (ts.tv_sec || ts.tv_nsec);
        }
 
        spin_lock_irq(¤t->sighand->siglock);
        sig = dequeue_signal(current, &these, &info);
-       if (!sig) {
-               timeout = MAX_SCHEDULE_TIMEOUT;
-               if (uts)
-                       timeout = (timespec_to_jiffies(&ts)
-                                  + (ts.tv_sec || ts.tv_nsec));
+       if (!sig && timeout) {
+               /*
+                * None ready -- temporarily unblock those we're
+                * interested while we are sleeping in so that we'll
+                * be awakened when they arrive.
+                */
+               current->real_blocked = current->blocked;
+               sigandsets(¤t->blocked, ¤t->blocked, &these);
+               recalc_sigpending();
+               spin_unlock_irq(¤t->sighand->siglock);
 
-               if (timeout) {
-                       /*
-                        * None ready -- temporarily unblock those we're
-                        * interested while we are sleeping in so that we'll
-                        * be awakened when they arrive.
-                        */
-                       current->real_blocked = current->blocked;
-                       sigandsets(¤t->blocked, ¤t->blocked, &these);
-                       recalc_sigpending();
-                       spin_unlock_irq(¤t->sighand->siglock);
-
-                       timeout = schedule_timeout_interruptible(timeout);
-
-                       spin_lock_irq(¤t->sighand->siglock);
-                       sig = dequeue_signal(current, &these, &info);
-                       current->blocked = current->real_blocked;
-                       siginitset(¤t->real_blocked, 0);
-                       recalc_sigpending();
-               }
+               timeout = schedule_timeout_interruptible(timeout);
+
+               spin_lock_irq(¤t->sighand->siglock);
+               sig = dequeue_signal(current, &these, &info);
+               current->blocked = current->real_blocked;
+               siginitset(¤t->real_blocked, 0);
+               recalc_sigpending();
        }
        spin_unlock_irq(¤t->sighand->siglock);