compat: Cleanup in_compat_syscall() callers
[linux-2.6-block.git] / kernel / time / time.c
index ccdb351277eecf739605be2e98b44174de595883..ad204cf6d0018ef99c00d4b30e942209b77d890c 100644 (file)
@@ -104,12 +104,12 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr)
 #ifdef CONFIG_COMPAT
 #ifdef __ARCH_WANT_COMPAT_SYS_TIME
 
-/* compat_time_t is a 32 bit "long" and needs to get converted. */
-COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
+/* old_time32_t is a 32 bit "long" and needs to get converted. */
+COMPAT_SYSCALL_DEFINE1(time, old_time32_t __user *, tloc)
 {
-       compat_time_t i;
+       old_time32_t i;
 
-       i = (compat_time_t)ktime_get_real_seconds();
+       i = (old_time32_t)ktime_get_real_seconds();
 
        if (tloc) {
                if (put_user(i,tloc))
@@ -119,7 +119,7 @@ COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
        return i;
 }
 
-COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr)
+COMPAT_SYSCALL_DEFINE1(stime, old_time32_t __user *, tptr)
 {
        struct timespec64 tv;
        int err;
@@ -144,9 +144,11 @@ SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv,
                struct timezone __user *, tz)
 {
        if (likely(tv != NULL)) {
-               struct timeval ktv;
-               do_gettimeofday(&ktv);
-               if (copy_to_user(tv, &ktv, sizeof(ktv)))
+               struct timespec64 ts;
+
+               ktime_get_real_ts64(&ts);
+               if (put_user(ts.tv_sec, &tv->tv_sec) ||
+                   put_user(ts.tv_nsec / 1000, &tv->tv_usec))
                        return -EFAULT;
        }
        if (unlikely(tz != NULL)) {
@@ -223,14 +225,15 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
 }
 
 #ifdef CONFIG_COMPAT
-COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
+COMPAT_SYSCALL_DEFINE2(gettimeofday, struct old_timeval32 __user *, tv,
                       struct timezone __user *, tz)
 {
        if (tv) {
-               struct timeval ktv;
+               struct timespec64 ts;
 
-               do_gettimeofday(&ktv);
-               if (compat_put_timeval(&ktv, tv))
+               ktime_get_real_ts64(&ts);
+               if (put_user(ts.tv_sec, &tv->tv_sec) ||
+                   put_user(ts.tv_nsec / 1000, &tv->tv_usec))
                        return -EFAULT;
        }
        if (tz) {
@@ -241,7 +244,7 @@ COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
        return 0;
 }
 
-COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv,
+COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv,
                       struct timezone __user *, tz)
 {
        struct timespec64 new_ts;
@@ -342,30 +345,6 @@ unsigned int jiffies_to_usecs(const unsigned long j)
 }
 EXPORT_SYMBOL(jiffies_to_usecs);
 
-/**
- * timespec_trunc - Truncate timespec to a granularity
- * @t: Timespec
- * @gran: Granularity in ns.
- *
- * Truncate a timespec to a granularity. Always rounds down. gran must
- * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
- */
-struct timespec timespec_trunc(struct timespec t, unsigned gran)
-{
-       /* Avoid division in the common cases 1 ns and 1 s. */
-       if (gran == 1) {
-               /* nothing */
-       } else if (gran == NSEC_PER_SEC) {
-               t.tv_nsec = 0;
-       } else if (gran > 1 && gran < NSEC_PER_SEC) {
-               t.tv_nsec -= t.tv_nsec % gran;
-       } else {
-               WARN(1, "illegal file time granularity: %u", gran);
-       }
-       return t;
-}
-EXPORT_SYMBOL(timespec_trunc);
-
 /*
  * mktime64 - Converts date to seconds.
  * Converts Gregorian date to seconds since 1970-01-01 00:00:00.
@@ -863,7 +842,7 @@ int get_timespec64(struct timespec64 *ts,
        ts->tv_sec = kts.tv_sec;
 
        /* Zero out the padding for 32 bit systems or in compat mode */
-       if (IS_ENABLED(CONFIG_64BIT_TIME) && (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()))
+       if (IS_ENABLED(CONFIG_64BIT_TIME) && in_compat_syscall())
                kts.tv_nsec &= 0xFFFFFFFFUL;
 
        ts->tv_nsec = kts.tv_nsec;
@@ -884,10 +863,10 @@ int put_timespec64(const struct timespec64 *ts,
 }
 EXPORT_SYMBOL_GPL(put_timespec64);
 
-int __compat_get_timespec64(struct timespec64 *ts64,
-                                  const struct compat_timespec __user *cts)
+static int __get_old_timespec32(struct timespec64 *ts64,
+                                  const struct old_timespec32 __user *cts)
 {
-       struct compat_timespec ts;
+       struct old_timespec32 ts;
        int ret;
 
        ret = copy_from_user(&ts, cts, sizeof(ts));
@@ -900,33 +879,33 @@ int __compat_get_timespec64(struct timespec64 *ts64,
        return 0;
 }
 
-int __compat_put_timespec64(const struct timespec64 *ts64,
-                                  struct compat_timespec __user *cts)
+static int __put_old_timespec32(const struct timespec64 *ts64,
+                                  struct old_timespec32 __user *cts)
 {
-       struct compat_timespec ts = {
+       struct old_timespec32 ts = {
                .tv_sec = ts64->tv_sec,
                .tv_nsec = ts64->tv_nsec
        };
        return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0;
 }
 
-int compat_get_timespec64(struct timespec64 *ts, const void __user *uts)
+int get_old_timespec32(struct timespec64 *ts, const void __user *uts)
 {
        if (COMPAT_USE_64BIT_TIME)
                return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
        else
-               return __compat_get_timespec64(ts, uts);
+               return __get_old_timespec32(ts, uts);
 }
-EXPORT_SYMBOL_GPL(compat_get_timespec64);
+EXPORT_SYMBOL_GPL(get_old_timespec32);
 
-int compat_put_timespec64(const struct timespec64 *ts, void __user *uts)
+int put_old_timespec32(const struct timespec64 *ts, void __user *uts)
 {
        if (COMPAT_USE_64BIT_TIME)
                return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
        else
-               return __compat_put_timespec64(ts, uts);
+               return __put_old_timespec32(ts, uts);
 }
-EXPORT_SYMBOL_GPL(compat_put_timespec64);
+EXPORT_SYMBOL_GPL(put_old_timespec32);
 
 int get_itimerspec64(struct itimerspec64 *it,
                        const struct __kernel_itimerspec __user *uit)
@@ -958,23 +937,23 @@ int put_itimerspec64(const struct itimerspec64 *it,
 }
 EXPORT_SYMBOL_GPL(put_itimerspec64);
 
-int get_compat_itimerspec64(struct itimerspec64 *its,
-                       const struct compat_itimerspec __user *uits)
+int get_old_itimerspec32(struct itimerspec64 *its,
+                       const struct old_itimerspec32 __user *uits)
 {
 
-       if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
-           __compat_get_timespec64(&its->it_value, &uits->it_value))
+       if (__get_old_timespec32(&its->it_interval, &uits->it_interval) ||
+           __get_old_timespec32(&its->it_value, &uits->it_value))
                return -EFAULT;
        return 0;
 }
-EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
+EXPORT_SYMBOL_GPL(get_old_itimerspec32);
 
-int put_compat_itimerspec64(const struct itimerspec64 *its,
-                       struct compat_itimerspec __user *uits)
+int put_old_itimerspec32(const struct itimerspec64 *its,
+                       struct old_itimerspec32 __user *uits)
 {
-       if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
-           __compat_put_timespec64(&its->it_value, &uits->it_value))
+       if (__put_old_timespec32(&its->it_interval, &uits->it_interval) ||
+           __put_old_timespec32(&its->it_value, &uits->it_value))
                return -EFAULT;
        return 0;
 }
-EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
+EXPORT_SYMBOL_GPL(put_old_itimerspec32);