Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 117593
b: refs/heads/master
c: df0cc05
h: refs/heads/master
i:
  117591: 91e3efb
v: v3
  • Loading branch information
Thomas Gleixner authored and Arjan van de Ven committed Sep 6, 2008
1 parent 279142d commit 43fe500
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7bb67439bf6bd3782f07f1d7be1e63406453d5de
refs/heads/master: df0cc0539b4127bd02f64de2c335b4af1fdb3845
4 changes: 4 additions & 0 deletions trunk/include/linux/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct timezone {
#define NSEC_PER_SEC 1000000000L
#define FSEC_PER_SEC 1000000000000000L

#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)

static inline int timespec_equal(const struct timespec *a,
const struct timespec *b)
{
Expand Down Expand Up @@ -72,6 +74,8 @@ 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, long nsec);
extern struct timespec timespec_add_safe(const struct timespec lhs,
const struct timespec rhs);

/*
* sub = lhs - rhs, in normalized form
Expand Down
18 changes: 18 additions & 0 deletions trunk/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 43fe500

Please sign in to comment.