提交 3f39894d 编写于 作者: G George Anzinger 提交者: Linus Torvalds

[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: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 09e12f9f
...@@ -101,7 +101,7 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran); ...@@ -101,7 +101,7 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
static inline void static inline void
set_normalized_timespec (struct timespec *ts, time_t sec, long nsec) set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
{ {
while (nsec > NSEC_PER_SEC) { while (nsec >= NSEC_PER_SEC) {
nsec -= NSEC_PER_SEC; nsec -= NSEC_PER_SEC;
++sec; ++sec;
} }
......
...@@ -270,7 +270,7 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff) ...@@ -270,7 +270,7 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff)
long sec = tp->tv_sec; long sec = tp->tv_sec;
long nsec = tp->tv_nsec + res - 1; long nsec = tp->tv_nsec + res - 1;
if (nsec > NSEC_PER_SEC) { if (nsec >= NSEC_PER_SEC) {
sec++; sec++;
nsec -= NSEC_PER_SEC; nsec -= NSEC_PER_SEC;
} }
...@@ -1209,13 +1209,9 @@ static int do_posix_clock_monotonic_get(clockid_t clock, struct timespec *tp) ...@@ -1209,13 +1209,9 @@ static int do_posix_clock_monotonic_get(clockid_t clock, struct timespec *tp)
do_posix_clock_monotonic_gettime_parts(tp, &wall_to_mono); do_posix_clock_monotonic_gettime_parts(tp, &wall_to_mono);
tp->tv_sec += wall_to_mono.tv_sec; set_normalized_timespec(tp, tp->tv_sec + wall_to_mono.tv_sec,
tp->tv_nsec += wall_to_mono.tv_nsec; tp->tv_nsec + wall_to_mono.tv_nsec);
if ((tp->tv_nsec - NSEC_PER_SEC) > 0) {
tp->tv_nsec -= NSEC_PER_SEC;
tp->tv_sec++;
}
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册