Skip to content

Commit

Permalink
[PATCH] Normalize timespec for negative values in ns_to_timespec
Browse files Browse the repository at this point in the history
- 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>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
George Anzinger authored and Linus Torvalds committed Feb 3, 2006
1 parent 034b91a commit 88fc389
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,16 @@ void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
*
* 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;
}
Expand Down

0 comments on commit 88fc389

Please sign in to comment.