From: George Anzinger <george@wildturkeyranch.net>
To: tglx@linutronix.de
Cc: Andrew Morton <akpm@osdl.org>, linux-kernel@vger.kernel.org
Subject: [PATCH] Normalize timespec for negative values in ns_to_timespec
Date: Sat, 21 Jan 2006 09:27:01 -0800 [thread overview]
Message-ID: <43D26EE5.90102@wildturkeyranch.net> (raw)
In-Reply-To: <1137839641.28034.62.camel@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 173 bytes --]
Here is the patch again. This time with a header.
--
George Anzinger george@wildturkeyranch.net
HRT (High-res-timers): http://sourceforge.net/projects/high-res-timers/
[-- Attachment #2: ktime_conversion.patch --]
[-- Type: text/plain, Size: 1252 bytes --]
Source: George Anzinger<george@wilturkeyranch.net>
Bug fix.
Description:
The timespec ns_to_timespec() inline in kernel/time.c mishandles
negative times in that it generates unnormalized timespecs.
There are several ways to handle this, the attached being the most
conservative.
Signed off: George Anzinger<george@wildturkeyranch.net>
kernel/time.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
Index: linux-2.6.16-rc/kernel/time.c
===================================================================
--- linux-2.6.16-rc.orig/kernel/time.c
+++ linux-2.6.16-rc/kernel/time.c
@@ -702,16 +702,19 @@ void set_normalized_timespec(struct time
*
* Returns the timespec representation of the nsec parameter.
*/
-inline struct timespec ns_to_timespec(const nsec_t nsec)
+struct timespec ns_to_timespec(const nsec_t nsec)
{
struct timespec ts;
- if (nsec)
+ if (!nsec) return (struct timespec){0, 0};
+
+ if (nsec < 0) {
+ ts.tv_sec = div_long_long_rem_signed(-nsec, NSEC_PER_SEC,
+ &ts.tv_nsec);
+ set_normalized_timespec(&ts, -ts.tv_sec, -ts.tv_nsec);
+ } else
ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC,
&ts.tv_nsec);
- else
- ts.tv_sec = ts.tv_nsec = 0;
-
return ts;
}
prev parent reply other threads:[~2006-01-21 17:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-21 10:02 [PATCH] Normalize timespec for negative values in ns_to_timespec Thomas Gleixner
2006-01-21 10:19 ` Andrew Morton
2006-01-21 10:34 ` Thomas Gleixner
2006-01-21 17:27 ` George Anzinger [this message]
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=43D26EE5.90102@wildturkeyranch.net \
--to=george@wildturkeyranch.net \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.