lkml.org 
[lkml]   [2015]   [Jun]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 11/24] posix-timers: Implement y2038 safe clock_set64() callback
Date
The clock_set() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback clock_set64() which uses
struct timespec64 along with a default implementation which is a
wrapper for the existing clock_set() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to clock_set64() and will be removed once this is
completed.

Use the new callback in __clock_settime().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
include/linux/posix-timers.h | 2 ++
kernel/time/posix-timers.c | 24 +++++++++++++++++++-----
2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 16c3364..2b19ec8 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -100,6 +100,8 @@ 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_set64) (const clockid_t which_clock,
+ const struct timespec64 *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
int (*timer_create) (struct k_itimer *timer);
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 65610ac..dcc632c 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -577,6 +577,18 @@ static int default_timer_set64(struct k_itimer *timr, int flags,
return ret;
}

+static int default_clock_set64(const clockid_t which_clock,
+ const struct timespec64 *tp64)
+{
+ struct k_clock *kc = clockid_to_kclock(which_clock);
+ struct timespec tp;
+ int ret;
+
+ tp = timespec64_to_timespec(*tp64);
+ ret = kc->clock_set(which_clock, &tp);
+ return ret;
+}
+
void posix_timers_register_clock(const clockid_t clock_id,
struct k_clock *new_clock)
{
@@ -601,6 +613,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
new_clock->timer_get64 = default_timer_get64;
if (new_clock->timer_set && !new_clock->timer_set64)
new_clock->timer_set64 = default_timer_set64;
+ if (new_clock->clock_set && !new_clock->clock_set64)
+ new_clock->clock_set64 = default_clock_set64;

posix_clocks[clock_id] = *new_clock;
}
@@ -1089,22 +1103,22 @@ void exit_itimers(struct signal_struct *sig)
}
}

-static int __clock_settime(clockid_t which_clock, struct timespec *ts)
+static int __clock_settime(clockid_t which_clock, struct timespec64 *ts)
{
struct k_clock *kc = clockid_to_kclock(which_clock);

- if (!kc || !kc->clock_set)
+ if (!kc || !kc->clock_set64)
return -EINVAL;

- return kc->clock_set(which_clock, ts);
+ return kc->clock_set64(which_clock, ts);
}

SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
{
- struct timespec new_tp;
+ struct timespec64 new_tp;

- if (copy_from_user(&new_tp, tp, sizeof (*tp)))
+ if (get_timespec(&new_tp, tp))
return -EFAULT;

return __clock_settime(which_clock, &new_tp);
--
1.7.9.5


\
 
 \ /
  Last update: 2015-06-12 10:21    [W:0.180 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site