From: George Anzinger <george@mvista.com>
To: Andrew Morton <akpm@osdl.org>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [PATCH] Timespec normalize off by one errors
Date: Fri, 11 Nov 2005 13:16:10 -0800 [thread overview]
Message-ID: <43750A1A.4010102@mvista.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 165 bytes --]
Found three places were we use ">" instead of ">=".
--
George Anzinger george@mvista.com
HRT (High-res-timers): http://sourceforge.net/projects/high-res-timers/
[-- Attachment #2: time-spec2.patch --]
[-- Type: text/plain, Size: 1633 bytes --]
Source: MontaVista Software, Inc.
Type: Defect Fix
It would appear that the timespec normalize code has an off by one error.
Found in three places.
Signed-off-by: George Anzinger<george@mvista.com>
include/linux/time.h | 2 +-
kernel/posix-timers.c | 10 +++-------
2 files changed, 4 insertions(+), 8 deletions(-)
Index: linux-2.6.15-rc/include/linux/time.h
===================================================================
--- linux-2.6.15-rc.orig/include/linux/time.h
+++ linux-2.6.15-rc/include/linux/time.h
@@ -101,7 +101,7 @@ extern struct timespec timespec_trunc(st
static inline void
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;
++sec;
}
Index: linux-2.6.15-rc/kernel/posix-timers.c
===================================================================
--- linux-2.6.15-rc.orig/kernel/posix-timers.c
+++ linux-2.6.15-rc/kernel/posix-timers.c
@@ -270,7 +270,7 @@ static void tstojiffie(struct timespec *
long sec = tp->tv_sec;
long nsec = tp->tv_nsec + res - 1;
- if (nsec > NSEC_PER_SEC) {
+ if (nsec >= NSEC_PER_SEC) {
sec++;
nsec -= NSEC_PER_SEC;
}
@@ -1209,13 +1209,9 @@ static int do_posix_clock_monotonic_get(
do_posix_clock_monotonic_gettime_parts(tp, &wall_to_mono);
- tp->tv_sec += wall_to_mono.tv_sec;
- tp->tv_nsec += wall_to_mono.tv_nsec;
+ set_normalized_timespec(tp, tp->tv_sec += wall_to_mono.tv_sec,
+ 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;
}
next reply other threads:[~2005-11-11 21:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-11 21:16 George Anzinger [this message]
[not found] ` <1131744325.9957.20.camel@localhost>
2005-11-11 22:15 ` [PATCH] Timespec normalize off by one errors George Anzinger
2005-11-11 22:25 ` George Anzinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43750A1A.4010102@mvista.com \
--to=george@mvista.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).