Commit 3f39894d1b5c253b10fcb8fbbbcf65a330f6cdc7

Authored by George Anzinger
Committed by Linus Torvalds
1 parent 09e12f9f6b

[PATCH] timespec: normalize off by one errors

It would appear that the timespec normalize code has an off by one error.
Found in three places.  Thanks to Ben for spotting.

Signed-off-by: George Anzinger<george@mvista.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 2 changed files with 4 additions and 8 deletions Side-by-side Diff

include/linux/time.h
... ... @@ -101,7 +101,7 @@
101 101 static inline void
102 102 set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
103 103 {
104   - while (nsec > NSEC_PER_SEC) {
  104 + while (nsec >= NSEC_PER_SEC) {
105 105 nsec -= NSEC_PER_SEC;
106 106 ++sec;
107 107 }
kernel/posix-timers.c
... ... @@ -270,7 +270,7 @@
270 270 long sec = tp->tv_sec;
271 271 long nsec = tp->tv_nsec + res - 1;
272 272  
273   - if (nsec > NSEC_PER_SEC) {
  273 + if (nsec >= NSEC_PER_SEC) {
274 274 sec++;
275 275 nsec -= NSEC_PER_SEC;
276 276 }
277 277  
... ... @@ -1209,13 +1209,9 @@
1209 1209  
1210 1210 do_posix_clock_monotonic_gettime_parts(tp, &wall_to_mono);
1211 1211  
1212   - tp->tv_sec += wall_to_mono.tv_sec;
1213   - tp->tv_nsec += wall_to_mono.tv_nsec;
  1212 + set_normalized_timespec(tp, tp->tv_sec + wall_to_mono.tv_sec,
  1213 + tp->tv_nsec + wall_to_mono.tv_nsec);
1214 1214  
1215   - if ((tp->tv_nsec - NSEC_PER_SEC) > 0) {
1216   - tp->tv_nsec -= NSEC_PER_SEC;
1217   - tp->tv_sec++;
1218   - }
1219 1215 return 0;
1220 1216 }
1221 1217