]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
time: Change k_clock clock_get() to use timespec64
authorDeepa Dinamani <deepa.kernel@gmail.com>
Sun, 26 Mar 2017 19:04:14 +0000 (12:04 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 14 Apr 2017 19:49:55 +0000 (21:49 +0200)
struct timespec is not y2038 safe on 32 bit machines.  Replace uses of
struct timespec with struct timespec64 in the kernel.

The syscall interfaces themselves will be changed in a separate series.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: y2038@lists.linaro.org
Cc: john.stultz@linaro.org
Cc: arnd@arndb.de
Link: http://lkml.kernel.org/r/1490555058-4603-4-git-send-email-deepa.kernel@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
drivers/char/mmtimer.c
include/linux/posix-timers.h
include/linux/timekeeping.h
kernel/time/alarmtimer.c
kernel/time/posix-clock.c
kernel/time/posix-cpu-timers.c
kernel/time/posix-stubs.c
kernel/time/posix-timers.c

index b708c85dc9c1d7b5d243c4add03cc2fe5936141a..40d880b8c02f0f74affdbbd3117827df64396968 100644 (file)
@@ -478,13 +478,13 @@ static int sgi_clock_period;
 static struct timespec sgi_clock_offset;
 static int sgi_clock_period;
 
-static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_get(clockid_t clockid, struct timespec64 *tp)
 {
        u64 nsec;
 
        nsec = rtc_time() * sgi_clock_period
                        + sgi_clock_offset.tv_nsec;
-       *tp = ns_to_timespec(nsec);
+       *tp = ns_to_timespec64(nsec);
        tp->tv_sec += sgi_clock_offset.tv_sec;
        return 0;
 };
index 64aa189efe21d6792b07f2b9005fcf5345b2e98c..0688f3975da70d2ab89c62a60347521318014eda 100644 (file)
@@ -90,7 +90,7 @@ struct k_clock {
        int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
        int (*clock_set) (const clockid_t which_clock,
                          const struct timespec *tp);
-       int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+       int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp);
        int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
        int (*timer_create) (struct k_itimer *timer);
        int (*nsleep) (const clockid_t which_clock, int flags,
index 3617a78897bb4a3db562815119c0b9e7be8fea9b..ddc229ff6d1ee1dbd3e535d7c0a2f16225c29f47 100644 (file)
@@ -258,6 +258,11 @@ static inline void timekeeping_clocktai(struct timespec *ts)
        *ts = ktime_to_timespec(ktime_get_clocktai());
 }
 
+static inline void timekeeping_clocktai64(struct timespec64 *ts)
+{
+       *ts = ktime_to_timespec64(ktime_get_clocktai());
+}
+
 /*
  * RTC specific
  */
index ce3a31e8eb3687e8633848d645ba4c4dc741a8f3..944ca6e6f1c22f213626e860408277e65a360dda 100644 (file)
@@ -558,14 +558,14 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
  *
  * Provides the underlying alarm base time.
  */
-static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
 {
        struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
 
        if (!alarmtimer_get_rtcdev())
                return -EINVAL;
 
-       *tp = ktime_to_timespec(base->gettime());
+       *tp = ktime_to_timespec64(base->gettime());
        return 0;
 }
 
index e24008c098c6b8ca149afe58e255a8c1303086d9..fab6bd33155e976b70c2c10b6b47ba68340010df 100644 (file)
@@ -297,20 +297,17 @@ out:
        return err;
 }
 
-static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+static int pc_clock_gettime(clockid_t id, struct timespec64 *ts)
 {
        struct posix_clock_desc cd;
-       struct timespec64 ts64;
        int err;
 
        err = get_clock_desc(id, &cd);
        if (err)
                return err;
 
-       if (cd.clk->ops.clock_gettime) {
-               err = cd.clk->ops.clock_gettime(cd.clk, &ts64);
-               *ts = timespec64_to_timespec(ts64);
-       }
+       if (cd.clk->ops.clock_gettime)
+               err = cd.clk->ops.clock_gettime(cd.clk, ts);
        else
                err = -EOPNOTSUPP;
 
index 76bea3a47d4bdae375c5a26be0a556821d1a1418..082231cc7953216b635a94f312a571c56fef9d46 100644 (file)
@@ -261,7 +261,7 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
                                    const clockid_t which_clock,
-                                   struct timespec *tp)
+                                   struct timespec64 *tp)
 {
        int err = -EINVAL;
        u64 rtn;
@@ -275,13 +275,13 @@ static int posix_cpu_clock_get_task(struct task_struct *tsk,
        }
 
        if (!err)
-               *tp = ns_to_timespec(rtn);
+               *tp = ns_to_timespec64(rtn);
 
        return err;
 }
 
 
-static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
+static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec64 *tp)
 {
        const pid_t pid = CPUCLOCK_PID(which_clock);
        int err = -EINVAL;
@@ -1374,7 +1374,7 @@ static int process_cpu_clock_getres(const clockid_t which_clock,
        return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
 static int process_cpu_clock_get(const clockid_t which_clock,
-                                struct timespec *tp)
+                                struct timespec64 *tp)
 {
        return posix_cpu_clock_get(PROCESS_CLOCK, tp);
 }
@@ -1399,7 +1399,7 @@ static int thread_cpu_clock_getres(const clockid_t which_clock,
        return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
 static int thread_cpu_clock_get(const clockid_t which_clock,
-                               struct timespec *tp)
+                               struct timespec64 *tp)
 {
        return posix_cpu_clock_get(THREAD_CLOCK, tp);
 }
index 95a1b1fc396808c0aad38177e909ea8389dceb84..0fbd0c5b95cad597bcc170779e79b7a8d4296048 100644 (file)
@@ -64,14 +64,17 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
                struct timespec __user *,tp)
 {
+       struct timespec64 kernel_tp64;
        struct timespec kernel_tp;
 
        switch (which_clock) {
-       case CLOCK_REALTIME: ktime_get_real_ts(&kernel_tp); break;
-       case CLOCK_MONOTONIC: ktime_get_ts(&kernel_tp); break;
-       case CLOCK_BOOTTIME: get_monotonic_boottime(&kernel_tp); break;
+       case CLOCK_REALTIME: ktime_get_real_ts64(&kernel_tp64); break;
+       case CLOCK_MONOTONIC: ktime_get_ts64(&kernel_tp64); break;
+       case CLOCK_BOOTTIME: get_monotonic_boottime64(&kernel_tp64); break;
        default: return -EINVAL;
        }
+
+       kernel_tp = timespec64_to_timespec(kernel_tp64);
        if (copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
                return -EFAULT;
        return 0;
index f215ef7927729fa2358e8c7e83aafa69665fd143..68170642c77ca1e46d96a2dcafcbf3a81d58f5c1 100644 (file)
@@ -204,9 +204,9 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
 }
 
 /* Get clock_realtime */
-static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
+static int posix_clock_realtime_get(clockid_t which_clock, struct timespec64 *tp)
 {
-       ktime_get_real_ts(tp);
+       ktime_get_real_ts64(tp);
        return 0;
 }
 
@@ -229,32 +229,32 @@ static int posix_clock_realtime_adj(const clockid_t which_clock,
 /*
  * Get monotonic time for posix timers
  */
-static int posix_ktime_get_ts(clockid_t which_clock, struct timespec *tp)
+static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp)
 {
-       ktime_get_ts(tp);
+       ktime_get_ts64(tp);
        return 0;
 }
 
 /*
  * Get monotonic-raw time for posix timers
  */
-static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec *tp)
+static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec64 *tp)
 {
-       getrawmonotonic(tp);
+       getrawmonotonic64(tp);
        return 0;
 }
 
 
-static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec *tp)
+static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec64 *tp)
 {
-       *tp = current_kernel_time();
+       *tp = current_kernel_time64();
        return 0;
 }
 
 static int posix_get_monotonic_coarse(clockid_t which_clock,
-                                               struct timespec *tp)
+                                               struct timespec64 *tp)
 {
-       *tp = get_monotonic_coarse();
+       *tp = get_monotonic_coarse64();
        return 0;
 }
 
@@ -264,15 +264,15 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp
        return 0;
 }
 
-static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
+static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp)
 {
-       get_monotonic_boottime(tp);
+       get_monotonic_boottime64(tp);
        return 0;
 }
 
-static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
+static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
 {
-       timekeeping_clocktai(tp);
+       timekeeping_clocktai64(tp);
        return 0;
 }
 
@@ -1032,13 +1032,15 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
                struct timespec __user *,tp)
 {
        struct k_clock *kc = clockid_to_kclock(which_clock);
+       struct timespec64 kernel_tp64;
        struct timespec kernel_tp;
        int error;
 
        if (!kc)
                return -EINVAL;
 
-       error = kc->clock_get(which_clock, &kernel_tp);
+       error = kc->clock_get(which_clock, &kernel_tp64);
+       kernel_tp = timespec64_to_timespec(kernel_tp64);
 
        if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
                error = -EFAULT;