linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Normalize timespec for negative values in ns_to_timespec
@ 2006-01-21 10:02 Thomas Gleixner
  2006-01-21 10:19 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2006-01-21 10:02 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, George Anzinger

[-- Attachment #1: ns_to_timespec_normalize_if_negative.patch --]
[-- Type: text/plain, Size: 1093 bytes --]

From: George Anzinger <george@wildturkeyranch.net>

In case of a negative nsec value the result of the division must be
normalized.
Remove inline from an exported function.

Signed-off-by: George Anzinger <george@wildturkeyranch.net>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


Index: linux-2.6.15/kernel/time.c
===================================================================
--- linux-2.6.15.orig/kernel/time.c
+++ linux-2.6.15/kernel/time.c
@@ -658,15 +658,16 @@ 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)
-		ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC,
-						     &ts.tv_nsec);
-	else
-		ts.tv_sec = ts.tv_nsec = 0;
+	if (!nsec)
+		return (struct timespec) {0, 0};
+
+	ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec);
+	if (unlikely(nsec < 0))
+		set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec);
 
 	return ts;
 }

--


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Normalize timespec for negative values in ns_to_timespec
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2006-01-21 10:19 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel, george

Thomas Gleixner <tglx@linutronix.de> wrote:
>
>    Cc: George Anzinger <george@wildturkeyfarm.net>
>  From: George Anzinger <george@wildturkeyranch.net>

How many email addresses does the man have, and which is preferred?

>  In case of a negative nsec value the result of the division must be
>  normalized.

What effect did this problem have?  oopses?  Userspace misbehaviour? ...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Normalize timespec for negative values in ns_to_timespec
  2006-01-21 10:19 ` Andrew Morton
@ 2006-01-21 10:34   ` Thomas Gleixner
  2006-01-21 17:27     ` George Anzinger
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2006-01-21 10:34 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, george

On Sat, 2006-01-21 at 02:19 -0800, Andrew Morton wrote:
> Thomas Gleixner <tglx@linutronix.de> wrote:
> >
> >    Cc: George Anzinger <george@wildturkeyfarm.net>
> >  From: George Anzinger <george@wildturkeyranch.net>
> 
> How many email addresses does the man have, and which is preferred?

Sorry, my bad. I copied the wrong one into the cc-list

<george@wildturkeyranch.net> is the correct one.

> >  In case of a negative nsec value the result of the division must be
> >  normalized.
> 
> What effect did this problem have?  oopses?  Userspace misbehaviour? ...

Both

	tglx



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Normalize timespec for negative values in ns_to_timespec
  2006-01-21 10:34   ` Thomas Gleixner
@ 2006-01-21 17:27     ` George Anzinger
  0 siblings, 0 replies; 4+ messages in thread
From: George Anzinger @ 2006-01-21 17:27 UTC (permalink / raw)
  To: tglx; +Cc: Andrew Morton, linux-kernel

[-- 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;
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-01-21 17:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).