Commit d340266e authored by Deepa Dinamani's avatar Deepa Dinamani Committed by Thomas Gleixner

time: Change posix clocks ops interfaces to use timespec64

struct timespec is not y2038 safe on 32 bit machines.

The posix clocks apis use struct timespec directly and through struct
itimerspec.

Replace the posix clock interfaces to use struct timespec64 and struct
itimerspec64 instead.  Also fix up their implementations accordingly.

Note that the clock_getres() interface has also been changed to use
timespec64 even though this particular interface is not affected by the
y2038 problem. This helps verification for internal kernel code for y2038
readiness by getting rid of time_t/ timeval/ timespec.
Signed-off-by: default avatarDeepa Dinamani <deepa.kernel@gmail.com>
Cc: arnd@arndb.de
Cc: y2038@lists.linaro.org
Cc: netdev@vger.kernel.org
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: john.stultz@linaro.org
Link: http://lkml.kernel.org/r/1490555058-4603-3-git-send-email-deepa.kernel@gmail.comSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 2ac00f17
...@@ -97,30 +97,26 @@ static s32 scaled_ppm_to_ppb(long ppm) ...@@ -97,30 +97,26 @@ static s32 scaled_ppm_to_ppb(long ppm)
/* posix clock implementation */ /* posix clock implementation */
static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp) static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
{ {
tp->tv_sec = 0; tp->tv_sec = 0;
tp->tv_nsec = 1; tp->tv_nsec = 1;
return 0; return 0;
} }
static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp) static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp)
{ {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
struct timespec64 ts = timespec_to_timespec64(*tp);
return ptp->info->settime64(ptp->info, &ts); return ptp->info->settime64(ptp->info, tp);
} }
static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp) static int ptp_clock_gettime(struct posix_clock *pc, struct timespec64 *tp)
{ {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
struct timespec64 ts;
int err; int err;
err = ptp->info->gettime64(ptp->info, &ts); err = ptp->info->gettime64(ptp->info, tp);
if (!err)
*tp = timespec64_to_timespec(ts);
return err; return err;
} }
...@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx) ...@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
ops = ptp->info; ops = ptp->info;
if (tx->modes & ADJ_SETOFFSET) { if (tx->modes & ADJ_SETOFFSET) {
struct timespec ts; struct timespec64 ts;
ktime_t kt; ktime_t kt;
s64 delta; s64 delta;
...@@ -146,7 +142,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx) ...@@ -146,7 +142,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC) if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC)
return -EINVAL; return -EINVAL;
kt = timespec_to_ktime(ts); kt = timespec64_to_ktime(ts);
delta = ktime_to_ns(kt); delta = ktime_to_ns(kt);
err = ops->adjtime(ops, delta); err = ops->adjtime(ops, delta);
} else if (tx->modes & ADJ_FREQUENCY) { } else if (tx->modes & ADJ_FREQUENCY) {
......
...@@ -59,23 +59,23 @@ struct posix_clock_operations { ...@@ -59,23 +59,23 @@ struct posix_clock_operations {
int (*clock_adjtime)(struct posix_clock *pc, struct timex *tx); int (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
int (*clock_gettime)(struct posix_clock *pc, struct timespec *ts); int (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
int (*clock_getres) (struct posix_clock *pc, struct timespec *ts); int (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
int (*clock_settime)(struct posix_clock *pc, int (*clock_settime)(struct posix_clock *pc,
const struct timespec *ts); const struct timespec64 *ts);
int (*timer_create) (struct posix_clock *pc, struct k_itimer *kit); int (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
int (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit); int (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
void (*timer_gettime)(struct posix_clock *pc, void (*timer_gettime)(struct posix_clock *pc,
struct k_itimer *kit, struct itimerspec *tsp); struct k_itimer *kit, struct itimerspec64 *tsp);
int (*timer_settime)(struct posix_clock *pc, int (*timer_settime)(struct posix_clock *pc,
struct k_itimer *kit, int flags, struct k_itimer *kit, int flags,
struct itimerspec *tsp, struct itimerspec *old); struct itimerspec64 *tsp, struct itimerspec64 *old);
/* /*
* Optional character device methods: * Optional character device methods:
*/ */
......
...@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx) ...@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
static int pc_clock_gettime(clockid_t id, struct timespec *ts) static int pc_clock_gettime(clockid_t id, struct timespec *ts)
{ {
struct posix_clock_desc cd; struct posix_clock_desc cd;
struct timespec64 ts64;
int err; int err;
err = get_clock_desc(id, &cd); err = get_clock_desc(id, &cd);
if (err) if (err)
return err; return err;
if (cd.clk->ops.clock_gettime) if (cd.clk->ops.clock_gettime) {
err = cd.clk->ops.clock_gettime(cd.clk, ts); err = cd.clk->ops.clock_gettime(cd.clk, &ts64);
*ts = timespec64_to_timespec(ts64);
}
else else
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -319,14 +322,17 @@ static int pc_clock_gettime(clockid_t id, struct timespec *ts) ...@@ -319,14 +322,17 @@ static int pc_clock_gettime(clockid_t id, struct timespec *ts)
static int pc_clock_getres(clockid_t id, struct timespec *ts) static int pc_clock_getres(clockid_t id, struct timespec *ts)
{ {
struct posix_clock_desc cd; struct posix_clock_desc cd;
struct timespec64 ts64;
int err; int err;
err = get_clock_desc(id, &cd); err = get_clock_desc(id, &cd);
if (err) if (err)
return err; return err;
if (cd.clk->ops.clock_getres) if (cd.clk->ops.clock_getres) {
err = cd.clk->ops.clock_getres(cd.clk, ts); err = cd.clk->ops.clock_getres(cd.clk, &ts64);
*ts = timespec64_to_timespec(ts64);
}
else else
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -337,6 +343,7 @@ static int pc_clock_getres(clockid_t id, struct timespec *ts) ...@@ -337,6 +343,7 @@ static int pc_clock_getres(clockid_t id, struct timespec *ts)
static int pc_clock_settime(clockid_t id, const struct timespec *ts) static int pc_clock_settime(clockid_t id, const struct timespec *ts)
{ {
struct timespec64 ts64 = timespec_to_timespec64(*ts);
struct posix_clock_desc cd; struct posix_clock_desc cd;
int err; int err;
...@@ -350,7 +357,7 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts) ...@@ -350,7 +357,7 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts)
} }
if (cd.clk->ops.clock_settime) if (cd.clk->ops.clock_settime)
err = cd.clk->ops.clock_settime(cd.clk, ts); err = cd.clk->ops.clock_settime(cd.clk, &ts64);
else else
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
out: out:
...@@ -403,29 +410,36 @@ static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts) ...@@ -403,29 +410,36 @@ static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
{ {
clockid_t id = kit->it_clock; clockid_t id = kit->it_clock;
struct posix_clock_desc cd; struct posix_clock_desc cd;
struct itimerspec64 ts64;
if (get_clock_desc(id, &cd)) if (get_clock_desc(id, &cd))
return; return;
if (cd.clk->ops.timer_gettime) if (cd.clk->ops.timer_gettime) {
cd.clk->ops.timer_gettime(cd.clk, kit, ts); cd.clk->ops.timer_gettime(cd.clk, kit, &ts64);
*ts = itimerspec64_to_itimerspec(&ts64);
}
put_clock_desc(&cd); put_clock_desc(&cd);
} }
static int pc_timer_settime(struct k_itimer *kit, int flags, static int pc_timer_settime(struct k_itimer *kit, int flags,
struct itimerspec *ts, struct itimerspec *old) struct itimerspec *ts, struct itimerspec *old)
{ {
struct itimerspec64 ts64 = itimerspec_to_itimerspec64(ts);
clockid_t id = kit->it_clock; clockid_t id = kit->it_clock;
struct posix_clock_desc cd; struct posix_clock_desc cd;
struct itimerspec64 old64;
int err; int err;
err = get_clock_desc(id, &cd); err = get_clock_desc(id, &cd);
if (err) if (err)
return err; return err;
if (cd.clk->ops.timer_settime) if (cd.clk->ops.timer_settime) {
err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old); err = cd.clk->ops.timer_settime(cd.clk, kit, flags, &ts64, &old64);
if (old)
*old = itimerspec64_to_itimerspec(&old64);
}
else else
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment