]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/time.c
drivers/net/gianfar_sysfs.c: update email address of Kumar Gala
[linux-2.6-omap-h63xx.git] / kernel / time.c
index fa569885e22bc38b9b1e304ad82e441796ba8e93..169e8329e0b63ba59ce29f438dd90f182280ce03 100644 (file)
@@ -154,6 +154,9 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
        static int firsttime = 1;
        int error = 0;
 
+       if (!timespec_valid(tv))
+               return -EINVAL;
+
        error = security_settime(tv, tz);
        if (error)
                return error;
@@ -561,28 +564,6 @@ void getnstimeofday(struct timespec *tv)
 EXPORT_SYMBOL_GPL(getnstimeofday);
 #endif
 
-void getnstimestamp(struct timespec *ts)
-{
-       unsigned int seq;
-       struct timespec wall2mono;
-
-       /* synchronize with settimeofday() changes */
-       do {
-               seq = read_seqbegin(&xtime_lock);
-               getnstimeofday(ts);
-               wall2mono = wall_to_monotonic;
-       } while(unlikely(read_seqretry(&xtime_lock, seq)));
-
-       /* adjust to monotonicaly-increasing values */
-       ts->tv_sec += wall2mono.tv_sec;
-       ts->tv_nsec += wall2mono.tv_nsec;
-       while (unlikely(ts->tv_nsec >= NSEC_PER_SEC)) {
-               ts->tv_nsec -= NSEC_PER_SEC;
-               ts->tv_sec++;
-       }
-}
-EXPORT_SYMBOL_GPL(getnstimestamp);
-
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
  * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
@@ -599,12 +580,15 @@ EXPORT_SYMBOL_GPL(getnstimestamp);
  * will already get problems at other places on 2038-01-19 03:14:08)
  */
 unsigned long
-mktime (unsigned int year, unsigned int mon,
-       unsigned int day, unsigned int hour,
-       unsigned int min, unsigned int sec)
+mktime(const unsigned int year0, const unsigned int mon0,
+       const unsigned int day, const unsigned int hour,
+       const unsigned int min, const unsigned int sec)
 {
-       if (0 >= (int) (mon -= 2)) {    /* 1..12 -> 11,12,1..10 */
-               mon += 12;              /* Puts Feb last since it has leap day */
+       unsigned int mon = mon0, year = year0;
+
+       /* 1..12 -> 11,12,1..10 */
+       if (0 >= (int) (mon -= 2)) {
+               mon += 12;      /* Puts Feb last since it has leap day */
                year -= 1;
        }
 
@@ -616,6 +600,8 @@ mktime (unsigned int year, unsigned int mon,
        )*60 + sec; /* finally seconds */
 }
 
+EXPORT_SYMBOL(mktime);
+
 /**
  * set_normalized_timespec - set timespec sec and nsec parts and normalize
  *
@@ -630,7 +616,7 @@ mktime (unsigned int year, unsigned int mon,
  *     0 <= tv_nsec < NSEC_PER_SEC
  * For negative values only the tv_sec field is negative !
  */
-void set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
+void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
 {
        while (nsec >= NSEC_PER_SEC) {
                nsec -= NSEC_PER_SEC;
@@ -644,6 +630,42 @@ void set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
        ts->tv_nsec = nsec;
 }
 
+/**
+ * ns_to_timespec - Convert nanoseconds to timespec
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timespec representation of the nsec parameter.
+ */
+inline struct timespec ns_to_timespec(const nsec_t nsec)
+{
+       struct timespec ts;
+
+       if (nsec)
+               ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC,
+                                                    &ts.tv_nsec);
+       else
+               ts.tv_sec = ts.tv_nsec = 0;
+
+       return ts;
+}
+
+/**
+ * ns_to_timeval - Convert nanoseconds to timeval
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timeval representation of the nsec parameter.
+ */
+struct timeval ns_to_timeval(const nsec_t nsec)
+{
+       struct timespec ts = ns_to_timespec(nsec);
+       struct timeval tv;
+
+       tv.tv_sec = ts.tv_sec;
+       tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000;
+
+       return tv;
+}
+
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void)
 {