Skip to content

Commit

Permalink
[PATCH] posix timers: fix normalization problem
Browse files Browse the repository at this point in the history
(We found this (after a customer complained) and it is in the kernel.org
kernel.  Seems that for CLOCK_MONOTONIC absolute timers and clock_nanosleep
calls both the request time and wall_to_monotonic are subtracted prior to
the normalize resulting in an overflow in the existing normalize test.
This causes the result to be shifted ~4 seconds ahead instead of ~2 seconds
back in time.)

The normalize code in posix-timers.c fails when the tv_nsec member is ~1.2
seconds negative.  This can happen on absolute timers (and
clock_nanosleeps) requested on CLOCK_MONOTONIC (both the request time and
wall_to_monotonic are subtracted resulting in the possibility of a number
close to -2 seconds.)

This fix uses the set_normalized_timespec() (which does not have an
overflow problem) to fix the problem and as a side effect makes the code
cleaner.

Signed-off-by: George Anzinger <george@mvista.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
George Anzinger authored and Linus Torvalds committed Jul 29, 2005
1 parent a2d76bd commit 78fa74a
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions kernel/posix-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,21 +896,10 @@ static int adjust_abs_time(struct k_clock *clock, struct timespec *tp,
jiffies_64_f = get_jiffies_64();
}
/*
* Take away now to get delta
* Take away now to get delta and normalize
*/
oc.tv_sec -= now.tv_sec;
oc.tv_nsec -= now.tv_nsec;
/*
* Normalize...
*/
while ((oc.tv_nsec - NSEC_PER_SEC) >= 0) {
oc.tv_nsec -= NSEC_PER_SEC;
oc.tv_sec++;
}
while ((oc.tv_nsec) < 0) {
oc.tv_nsec += NSEC_PER_SEC;
oc.tv_sec--;
}
set_normalized_timespec(&oc, oc.tv_sec - now.tv_sec,
oc.tv_nsec - now.tv_nsec);
}else{
jiffies_64_f = get_jiffies_64();
}
Expand Down

0 comments on commit 78fa74a

Please sign in to comment.