diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2008-08-31 08:09:53 -0700 |
---|---|---|
committer | Arjan van de Ven <arjan@linux.intel.com> | 2008-09-05 21:34:57 -0700 |
commit | df0cc0539b4127bd02f64de2c335b4af1fdb3845 (patch) | |
tree | 2ba23487a2a6c37cfdcd1f5c9edb31a5e0b0df22 /kernel | |
parent | 7bb67439bf6bd3782f07f1d7be1e63406453d5de (diff) | |
download | blackbird-op-linux-df0cc0539b4127bd02f64de2c335b4af1fdb3845.tar.gz blackbird-op-linux-df0cc0539b4127bd02f64de2c335b4af1fdb3845.zip |
select: add a timespec_add_safe() function
For the select() rework, it's important to be able to add timespec
structures in an overflow-safe manner.
This patch adds a timespec_add_safe() function for this which is similar in
operation to ktime_add_safe(), but works on a struct timespec.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/time.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/time.c b/kernel/time.c index 6a08660b4fac..d63a4336fad6 100644 --- a/kernel/time.c +++ b/kernel/time.c @@ -669,3 +669,21 @@ EXPORT_SYMBOL(get_jiffies_64); #endif EXPORT_SYMBOL(jiffies); + +/* + * Add two timespec values and do a safety check for overflow. + * It's assumed that both values are valid (>= 0) + */ +struct timespec timespec_add_safe(const struct timespec lhs, + const struct timespec rhs) +{ + struct timespec res; + + set_normalized_timespec(&res, lhs.tv_sec + rhs.tv_sec, + lhs.tv_nsec + rhs.tv_nsec); + + if (res.tv_sec < lhs.tv_sec || res.tv_sec < rhs.tv_sec) + res.tv_sec = TIME_T_MAX; + + return res; +} |