From 765b1db8f8dce2bdfe58d64474c947b51a81d4a9 Mon Sep 17 00:00:00 2001 From: John Stultz Date: Tue, 13 Jul 2010 17:56:19 -0700 Subject: [PATCH] --- yaml --- r: 206143 b: refs/heads/master c: ce3bf7ab22527183634a76512d9854a38615e4d5 h: refs/heads/master i: 206141: 5b5e3ffc9cc57b985209796e9035ab21b23051f8 206139: bcc44f1f52d89062d4bb7585cb43138b10871940 206135: 7010e7c88c76961be4cf9f4c96a0c669365e320e 206127: e73253545bee7dac5d721b5facb2796cec8a34fc 206111: bf6a20d83f3ac92fca9cd3b4ea1ac7d449977809 206079: e87a7352760a0eb7acd1b27d537cd68f3e07da3a v: v3 --- [refs] | 2 +- trunk/include/linux/time.h | 16 ++++++++++++++++ trunk/kernel/time/timekeeping.c | 6 +++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 4efca8cccd09..f67d602a6ce5 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 8c73626ab28527b7eb7f3061c027fbfe530c488c +refs/heads/master: ce3bf7ab22527183634a76512d9854a38615e4d5 diff --git a/trunk/include/linux/time.h b/trunk/include/linux/time.h index ea3559f0b3f2..9072df83de1f 100644 --- a/trunk/include/linux/time.h +++ b/trunk/include/linux/time.h @@ -76,9 +76,25 @@ extern unsigned long mktime(const unsigned int year, const unsigned int mon, const unsigned int min, const unsigned int sec); extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); + +/* + * timespec_add_safe assumes both values are positive and checks + * for overflow. It will return TIME_T_MAX if the reutrn would be + * smaller then either of the arguments. + */ extern struct timespec timespec_add_safe(const struct timespec lhs, const struct timespec rhs); + +static inline struct timespec timespec_add(struct timespec lhs, + struct timespec rhs) +{ + struct timespec ts_delta; + set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec, + lhs.tv_nsec + rhs.tv_nsec); + return ts_delta; +} + /* * sub = lhs - rhs, in normalized form */ diff --git a/trunk/kernel/time/timekeeping.c b/trunk/kernel/time/timekeeping.c index caf8d4d4f5c8..623fe3d504dc 100644 --- a/trunk/kernel/time/timekeeping.c +++ b/trunk/kernel/time/timekeeping.c @@ -579,9 +579,9 @@ static int timekeeping_resume(struct sys_device *dev) if (timespec_compare(&ts, &timekeeping_suspend_time) > 0) { ts = timespec_sub(ts, timekeeping_suspend_time); - xtime = timespec_add_safe(xtime, ts); + xtime = timespec_add(xtime, ts); wall_to_monotonic = timespec_sub(wall_to_monotonic, ts); - total_sleep_time = timespec_add_safe(total_sleep_time, ts); + total_sleep_time = timespec_add(total_sleep_time, ts); } /* re-base the last cycle value */ timekeeper.clock->cycle_last = timekeeper.clock->read(timekeeper.clock); @@ -887,7 +887,7 @@ EXPORT_SYMBOL_GPL(getboottime); */ void monotonic_to_bootbased(struct timespec *ts) { - *ts = timespec_add_safe(*ts, total_sleep_time); + *ts = timespec_add(*ts, total_sleep_time); } EXPORT_SYMBOL_GPL(monotonic_to_bootbased);