Commit 5f82b2b77e66d452c3037cc47f436d2d76fd5f06

Authored by Thomas Gleixner
Committed by Linus Torvalds
1 parent 2a69897194

[PATCH] hrtimer: create and use timespec_valid macro

add timespec_valid(ts) [returns false if the timespec is denorm]

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 2 changed files with 8 additions and 3 deletions Side-by-side Diff

include/linux/time.h
... ... @@ -44,6 +44,12 @@
44 44  
45 45 extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec);
46 46  
  47 +/*
  48 + * Returns true if the timespec is norm, false if denorm:
  49 + */
  50 +#define timespec_valid(ts) \
  51 + (((ts)->tv_sec >= 0) && (((unsigned) (ts)->tv_nsec) < NSEC_PER_SEC))
  52 +
47 53 extern struct timespec xtime;
48 54 extern struct timespec wall_to_monotonic;
49 55 extern seqlock_t xtime_lock;
kernel/posix-timers.c
... ... @@ -712,8 +712,7 @@
712 712 */
713 713 static int good_timespec(const struct timespec *ts)
714 714 {
715   - if ((!ts) || (ts->tv_sec < 0) ||
716   - ((unsigned) ts->tv_nsec >= NSEC_PER_SEC))
  715 + if ((!ts) || !timespec_valid(ts))
717 716 return 0;
718 717 return 1;
719 718 }
... ... @@ -1406,7 +1405,7 @@
1406 1405 if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
1407 1406 return -EFAULT;
1408 1407  
1409   - if ((unsigned) t.tv_nsec >= NSEC_PER_SEC || t.tv_sec < 0)
  1408 + if (!timespec_valid(&t))
1410 1409 return -EINVAL;
1411 1410  
1412 1411 /*