As we change the user space type for the timerfd and posix timer
functions to __kernel_itimerspec, we need some form of conversion
helpers to avoid duplicating that logic.

Signed-off-by: Arnd Bergmann <[email protected]>
---
 include/linux/posix-timers.h |  5 +++++
 kernel/time/posix-timers.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 907f3fd191ac..bc44076f7e0b 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -137,5 +137,10 @@ void set_process_cpu_timer(struct task_struct *task, 
unsigned int clock_idx,
 long clock_nanosleep_restart(struct restart_block *restart_block);
 
 void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
+int get_itimerspec(struct itimerspec *it,
+                  const struct __kernel_itimerspec __user *uit);
+int put_itimerspec(const struct itimerspec *it,
+                  struct __kernel_itimerspec __user *uit);
+
 
 #endif
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 31ea01f42e1f..c99b10725025 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -794,6 +794,40 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
        return ret;
 }
 
+int get_itimerspec(struct itimerspec *it, const struct __kernel_itimerspec 
__user *uit)
+{
+       int ret;
+       struct timespec64 ts;
+
+       ret = get_timespec64(&ts, &uit->it_interval);
+       if (ret)
+               return ret;
+       it->it_interval = timespec64_to_timespec(ts);
+
+       ret = get_timespec64(&ts, &uit->it_value);
+       if (ret)
+               return ret;
+       it->it_value = timespec64_to_timespec(ts);
+
+       return ret;
+}
+
+int put_itimerspec(const struct itimerspec *it, struct __kernel_itimerspec 
__user *uit)
+{
+       int ret;
+       struct timespec64 ts;
+
+       ts = timespec_to_timespec64(it->it_interval);
+       ret = put_timespec64(&ts, &uit->it_interval);
+       if (ret)
+               return ret;
+
+       ts = timespec_to_timespec64(it->it_value);
+       ret = put_timespec64(&ts, &uit->it_value);
+
+       return ret;
+}
+
 /*
  * Get the number of overruns of a POSIX.1b interval timer.  This is to
  * be the overrun of the timer last delivered.  At the same time we are
-- 
2.1.0.rc2

_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038

Reply via email to