Commit 88fc3897 authored by George Anzinger's avatar George Anzinger Committed by Linus Torvalds

[PATCH] Normalize timespec for negative values in ns_to_timespec

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

- Remove inline from an exported function.
Signed-off-by: default avatarGeorge Anzinger <george@wildturkeyranch.net>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 034b91a3
...@@ -637,15 +637,16 @@ void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec) ...@@ -637,15 +637,16 @@ void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
* *
* Returns the timespec representation of the nsec parameter. * 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; struct timespec ts;
if (nsec) if (!nsec)
ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, return (struct timespec) {0, 0};
&ts.tv_nsec);
else ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec);
ts.tv_sec = ts.tv_nsec = 0; if (unlikely(nsec < 0))
set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec);
return ts; return ts;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment