Index: sys/compat/linux/linux_time.c =================================================================== --- sys/compat/linux/linux_time.c +++ sys/compat/linux/linux_time.c @@ -142,7 +142,7 @@ linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp) { - if (ltp->tv_sec < 0 || ltp->tv_nsec < 0 || ltp->tv_nsec > 999999999) + if (!timespecvalid(ltp)) return (EINVAL); ntp->tv_sec = ltp->tv_sec; ntp->tv_nsec = ltp->tv_nsec; @@ -165,7 +165,7 @@ linux_to_native_timespec64(struct timespec *ntp, struct l_timespec64 *ltp64) { - if (ltp64->tv_sec < 0 || ltp64->tv_nsec < 0 || ltp64->tv_nsec > 999999999) + if (!timespecvalid(ltp64)) return (EINVAL); ntp->tv_sec = ltp64->tv_sec; ntp->tv_nsec = ltp64->tv_nsec; Index: sys/kern/kern_event.c =================================================================== --- sys/kern/kern_event.c +++ sys/kern/kern_event.c @@ -1930,8 +1930,7 @@ rsbt = 0; if (tsp != NULL) { - if (tsp->tv_sec < 0 || tsp->tv_nsec < 0 || - tsp->tv_nsec >= 1000000000) { + if (!timespecvalid(tsp)) { error = EINVAL; goto done_nl; } Index: sys/kern/kern_time.c =================================================================== --- sys/kern/kern_time.c +++ sys/kern/kern_time.c @@ -411,7 +411,7 @@ return (error); if (clock_id != CLOCK_REALTIME) return (EINVAL); - if (ats->tv_nsec < 0 || ats->tv_nsec >= NS_PER_SEC || ats->tv_sec < 0) + if (!timespecvalid(ats)) return (EINVAL); if (!allow_insane_settime && (ats->tv_sec > 8000ULL * 365 * 24 * 60 * 60 || @@ -1644,7 +1644,7 @@ itimespecfix(struct timespec *ts) { - if (ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= NS_PER_SEC) + if (!timespecvalid(ts)) return (EINVAL); if ((UINT64_MAX - ts->tv_nsec) / NS_PER_SEC < ts->tv_sec) return (EINVAL); Index: sys/kern/kern_umtx.c =================================================================== --- sys/kern/kern_umtx.c +++ sys/kern/kern_umtx.c @@ -3772,9 +3772,7 @@ error = copyin(uaddr, tsp, sizeof(*tsp)); if (error == 0) { - if (tsp->tv_sec < 0 || - tsp->tv_nsec >= 1000000000 || - tsp->tv_nsec < 0) + if (!timespecvalid(tsp)) error = EINVAL; } return (error); @@ -4640,9 +4638,7 @@ error = copyin(uaddr, &ts32, sizeof(ts32)); if (error == 0) { - if (ts32.tv_sec < 0 || - ts32.tv_nsec >= 1000000000 || - ts32.tv_nsec < 0) + if (timespecvalid(&ts32)) error = EINVAL; else { CP(ts32, *tsp, tv_sec); @@ -4704,9 +4700,7 @@ error = copyin(uaddr, &ts32, sizeof(ts32)); if (error == 0) { - if (ts32.tv_sec < 0 || - ts32.tv_nsec >= 1000000000 || - ts32.tv_nsec < 0) + if (timespecvalid(&ts32)) error = EINVAL; else { CP(ts32, *tsp, tv_sec); @@ -4730,8 +4724,7 @@ error = copyin(uaddr, &t32, sizeof(t32)); if (error != 0) return (error); - if (t32._timeout.tv_sec < 0 || - t32._timeout.tv_nsec >= 1000000000 || t32._timeout.tv_nsec < 0) + if (!timespecvalid(&t32._timeout)) return (EINVAL); TS_CP(t32, *tp, _timeout); CP(t32, *tp, _flags); Index: sys/kern/sys_generic.c =================================================================== --- sys/kern/sys_generic.c +++ sys/kern/sys_generic.c @@ -1501,9 +1501,7 @@ precision = 0; if (tsp != NULL) { - if (tsp->tv_sec < 0) - return (EINVAL); - if (tsp->tv_nsec < 0 || tsp->tv_nsec >= 1000000000) + if (!timespecvalid(tsp)) return (EINVAL); if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) sbt = 0; Index: sys/sys/time.h =================================================================== --- sys/sys/time.h +++ sys/sys/time.h @@ -404,6 +404,8 @@ (vsp)->tv_nsec += 1000000000L; \ } \ } while (0) +#define timespecvalid(tsp) ((tsp)->tv_sec >= 0 && \ + (tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L) #ifdef _KERNEL