diff options
Diffstat (limited to 'include/linux/time.h')
-rw-r--r-- | include/linux/time.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index c81c5e40fcb5..b51e664c83e7 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
@@ -107,11 +107,36 @@ 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 | return true; | ||
129 | } | ||
130 | |||
131 | static inline bool timespec_valid_strict(const struct timespec *ts) | ||
132 | { | ||
133 | if (!timespec_valid(ts)) | ||
134 | return false; | ||
135 | /* Disallow values that could overflow ktime_t */ | ||
136 | if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) | ||
137 | return false; | ||
138 | return true; | ||
139 | } | ||
115 | 140 | ||
116 | extern void read_persistent_clock(struct timespec *ts); | 141 | extern void read_persistent_clock(struct timespec *ts); |
117 | extern void read_boot_clock(struct timespec *ts); | 142 | extern void read_boot_clock(struct timespec *ts); |