From: Thomas Gleixner Date: Tue, 10 Jan 2006 04:52:29 +0000 (-0800) Subject: [PATCH] hrtimer: create and use timespec_valid macro X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5f82b2b77e66d452c3037cc47f436d2d76fd5f06;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git [PATCH] hrtimer: create and use timespec_valid macro add timespec_valid(ts) [returns false if the timespec is denorm] Signed-off-by: Thomas Gleixner Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/include/linux/time.h b/include/linux/time.h index 4d49cabb9b47..64e797464589 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -44,6 +44,12 @@ extern unsigned long mktime(const unsigned int year, const unsigned int mon, extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec); +/* + * Returns true if the timespec is norm, false if denorm: + */ +#define timespec_valid(ts) \ + (((ts)->tv_sec >= 0) && (((unsigned) (ts)->tv_nsec) < NSEC_PER_SEC)) + extern struct timespec xtime; extern struct timespec wall_to_monotonic; extern seqlock_t xtime_lock; diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index 69d5a4b5395b..6b851a1bf4b0 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c @@ -712,8 +712,7 @@ out: */ static int good_timespec(const struct timespec *ts) { - if ((!ts) || (ts->tv_sec < 0) || - ((unsigned) ts->tv_nsec >= NSEC_PER_SEC)) + if ((!ts) || !timespec_valid(ts)) return 0; return 1; } @@ -1406,7 +1405,7 @@ sys_clock_nanosleep(const clockid_t which_clock, int flags, if (copy_from_user(&t, rqtp, sizeof (struct timespec))) return -EFAULT; - if ((unsigned) t.tv_nsec >= NSEC_PER_SEC || t.tv_sec < 0) + if (!timespec_valid(&t)) return -EINVAL; /*