[patch 11/21] Create and use timespec_valid macro

From: tglx
Date: Mon Dec 05 2005 - 19:38:07 EST



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

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>

include/linux/time.h | 6 ++++++
kernel/posix-timers.c | 5 ++---
2 files changed, 8 insertions(+), 3 deletions(-)

Index: linux-2.6.15-rc5/include/linux/time.h
===================================================================
--- linux-2.6.15-rc5.orig/include/linux/time.h
+++ linux-2.6.15-rc5/include/linux/time.h
@@ -44,6 +44,12 @@ extern unsigned long mktime(const unsign

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;
Index: linux-2.6.15-rc5/kernel/posix-timers.c
===================================================================
--- linux-2.6.15-rc5.orig/kernel/posix-timers.c
+++ linux-2.6.15-rc5/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 whic
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;

/*

--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/