Commit d1537fd1 authored by Linus Torvalds's avatar Linus Torvalds

Fix nanosleep() problem noticed by Todd Mokros <tmokros@neo.rr.com>.

If we raced on a timer expire, we'd get a negative timeout and think
that is was a _huge_ positive timeout. 
parent 063b1487
...@@ -1273,7 +1273,7 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave) ...@@ -1273,7 +1273,7 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave)
spin_unlock_irq(&nanosleep_abs_list_lock); spin_unlock_irq(&nanosleep_abs_list_lock);
} }
if (active) { if (active) {
unsigned long jiffies_f = jiffies; long jiffies_left;
/* /*
* Always restart abs calls from scratch to pick up any * Always restart abs calls from scratch to pick up any
...@@ -1282,7 +1282,12 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave) ...@@ -1282,7 +1282,12 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave)
if (abs) if (abs)
return -ERESTARTNOHAND; return -ERESTARTNOHAND;
jiffies_to_timespec(new_timer.expires - jiffies_f, tsave); jiffies_left = new_timer.expires - jiffies;
if (jiffies_left < 0)
return 0;
jiffies_to_timespec(jiffies_left, tsave);
while (tsave->tv_nsec < 0) { while (tsave->tv_nsec < 0) {
tsave->tv_nsec += NSEC_PER_SEC; tsave->tv_nsec += NSEC_PER_SEC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment