diff options
Diffstat (limited to 'include/linux/time.h')
-rw-r--r-- | include/linux/time.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index c81c5e40fcb5..b0bbd8f0130d 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
@@ -107,11 +107,29 @@ static inline struct timespec timespec_sub(struct timespec lhs, | |||
107 | return ts_delta; | 107 | return ts_delta; |
108 | } | 108 | } |
109 | 109 | ||
110 | #define KTIME_MAX ((s64)~((u64)1 << 63)) | ||
111 | #if (BITS_PER_LONG == 64) | ||
112 | # define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) | ||
113 | #else | ||
114 | # define KTIME_SEC_MAX LONG_MAX | ||
115 | #endif | ||
116 | |||
110 | /* | 117 | /* |
111 | * Returns true if the timespec is norm, false if denorm: | 118 | * Returns true if the timespec is norm, false if denorm: |
112 | */ | 119 | */ |
113 | #define timespec_valid(ts) \ | 120 | static inline bool timespec_valid(const struct timespec *ts) |
114 | (((ts)->tv_sec >= 0) && (((unsigned long) (ts)->tv_nsec) < NSEC_PER_SEC)) | 121 | { |
122 | /* Dates before 1970 are bogus */ | ||
123 | if (ts->tv_sec < 0) | ||
124 | return false; | ||
125 | /* Can't have more nanoseconds then a second */ | ||
126 | if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) | ||
127 | return false; | ||
128 | /* Disallow values that could overflow ktime_t */ | ||
129 | if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) | ||
130 | return false; | ||
131 | return true; | ||
132 | } | ||
115 | 133 | ||
116 | extern void read_persistent_clock(struct timespec *ts); | 134 | extern void read_persistent_clock(struct timespec *ts); |
117 | extern void read_boot_clock(struct timespec *ts); | 135 | extern void read_boot_clock(struct timespec *ts); |