From d1537fd1c7a1fa9303467825eb5a764cb229df10 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 9 Mar 2003 02:48:06 -0800 Subject: [PATCH] Fix nanosleep() problem noticed by Todd Mokros . If we raced on a timer expire, we'd get a negative timeout and think that is was a _huge_ positive timeout. --- kernel/posix-timers.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index add2e8abd7104..19e2aa5dcb41d 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c @@ -1273,7 +1273,7 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave) spin_unlock_irq(&nanosleep_abs_list_lock); } if (active) { - unsigned long jiffies_f = jiffies; + long jiffies_left; /* * 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) if (abs) 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) { tsave->tv_nsec += NSEC_PER_SEC; -- 2.53.0