linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	George Anzinger <george@wildturkeyfarm.net>
Subject: [PATCH] Normalize timespec for negative values in ns_to_timespec
Date: Sat, 21 Jan 2006 10:02:19 -0000	[thread overview]
Message-ID: <20060121094137.049533000@localhost.localdomain> (raw)

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

--


             reply	other threads:[~2006-01-21 10:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-21 10:02 Thomas Gleixner [this message]
2006-01-21 10:19 ` [PATCH] Normalize timespec for negative values in ns_to_timespec Andrew Morton
2006-01-21 10:34   ` Thomas Gleixner
2006-01-21 17:27     ` 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=20060121094137.049533000@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=akpm@osdl.org \
    --cc=george@wildturkeyfarm.net \
    --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).