Skip to content

Commit d340266

Browse files
deepa-hubKAGA-KOKO
authored andcommitted
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: Deepa 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.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 2ac00f1 commit d340266

3 files changed

Lines changed: 36 additions & 26 deletions

File tree

‎drivers/ptp/ptp_clock.c‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,26 @@ static s32 scaled_ppm_to_ppb(long ppm)
9797

9898
/* posix clock implementation */
9999

100-
static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)
100+
static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
101101
{
102102
tp->tv_sec = 0;
103103
tp->tv_nsec = 1;
104104
return 0;
105105
}
106106

107-
static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp)
107+
static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp)
108108
{
109109
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
110-
struct timespec64 ts = timespec_to_timespec64(*tp);
111110

112-
return ptp->info->settime64(ptp->info, &ts);
111+
return ptp->info->settime64(ptp->info, tp);
113112
}
114113

115-
static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp)
114+
static int ptp_clock_gettime(struct posix_clock *pc, struct timespec64 *tp)
116115
{
117116
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
118-
struct timespec64 ts;
119117
int err;
120118

121-
err = ptp->info->gettime64(ptp->info, &ts);
122-
if (!err)
123-
*tp = timespec64_to_timespec(ts);
119+
err = ptp->info->gettime64(ptp->info, tp);
124120
return err;
125121
}
126122

@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
133129
ops = ptp->info;
134130

135131
if (tx->modes & ADJ_SETOFFSET) {
136-
struct timespec ts;
132+
struct timespec64 ts;
137133
ktime_t kt;
138134
s64 delta;
139135

@@ -146,7 +142,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
146142
if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC)
147143
return -EINVAL;
148144

149-
kt = timespec_to_ktime(ts);
145+
kt = timespec64_to_ktime(ts);
150146
delta = ktime_to_ns(kt);
151147
err = ops->adjtime(ops, delta);
152148
} else if (tx->modes & ADJ_FREQUENCY) {

‎include/linux/posix-clock.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ struct posix_clock_operations {
5959

6060
int (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
6161

62-
int (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
62+
int (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
6363

64-
int (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
64+
int (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
6565

6666
int (*clock_settime)(struct posix_clock *pc,
67-
const struct timespec *ts);
67+
const struct timespec64 *ts);
6868

6969
int (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
7070

7171
int (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
7272

7373
void (*timer_gettime)(struct posix_clock *pc,
74-
struct k_itimer *kit, struct itimerspec *tsp);
74+
struct k_itimer *kit, struct itimerspec64 *tsp);
7575

7676
int (*timer_settime)(struct posix_clock *pc,
7777
struct k_itimer *kit, int flags,
78-
struct itimerspec *tsp, struct itimerspec *old);
78+
struct itimerspec64 *tsp, struct itimerspec64 *old);
7979
/*
8080
* Optional character device methods:
8181
*/

‎kernel/time/posix-clock.c‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
300300
static int pc_clock_gettime(clockid_t id, struct timespec *ts)
301301
{
302302
struct posix_clock_desc cd;
303+
struct timespec64 ts64;
303304
int err;
304305

305306
err = get_clock_desc(id, &cd);
306307
if (err)
307308
return err;
308309

309-
if (cd.clk->ops.clock_gettime)
310-
err = cd.clk->ops.clock_gettime(cd.clk, ts);
310+
if (cd.clk->ops.clock_gettime) {
311+
err = cd.clk->ops.clock_gettime(cd.clk, &ts64);
312+
*ts = timespec64_to_timespec(ts64);
313+
}
311314
else
312315
err = -EOPNOTSUPP;
313316

@@ -319,14 +322,17 @@ static int pc_clock_gettime(clockid_t id, struct timespec *ts)
319322
static int pc_clock_getres(clockid_t id, struct timespec *ts)
320323
{
321324
struct posix_clock_desc cd;
325+
struct timespec64 ts64;
322326
int err;
323327

324328
err = get_clock_desc(id, &cd);
325329
if (err)
326330
return err;
327331

328-
if (cd.clk->ops.clock_getres)
329-
err = cd.clk->ops.clock_getres(cd.clk, ts);
332+
if (cd.clk->ops.clock_getres) {
333+
err = cd.clk->ops.clock_getres(cd.clk, &ts64);
334+
*ts = timespec64_to_timespec(ts64);
335+
}
330336
else
331337
err = -EOPNOTSUPP;
332338

@@ -337,6 +343,7 @@ static int pc_clock_getres(clockid_t id, struct timespec *ts)
337343

338344
static int pc_clock_settime(clockid_t id, const struct timespec *ts)
339345
{
346+
struct timespec64 ts64 = timespec_to_timespec64(*ts);
340347
struct posix_clock_desc cd;
341348
int err;
342349

@@ -350,7 +357,7 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts)
350357
}
351358

352359
if (cd.clk->ops.clock_settime)
353-
err = cd.clk->ops.clock_settime(cd.clk, ts);
360+
err = cd.clk->ops.clock_settime(cd.clk, &ts64);
354361
else
355362
err = -EOPNOTSUPP;
356363
out:
@@ -403,29 +410,36 @@ static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
403410
{
404411
clockid_t id = kit->it_clock;
405412
struct posix_clock_desc cd;
413+
struct itimerspec64 ts64;
406414

407415
if (get_clock_desc(id, &cd))
408416
return;
409417

410-
if (cd.clk->ops.timer_gettime)
411-
cd.clk->ops.timer_gettime(cd.clk, kit, ts);
412-
418+
if (cd.clk->ops.timer_gettime) {
419+
cd.clk->ops.timer_gettime(cd.clk, kit, &ts64);
420+
*ts = itimerspec64_to_itimerspec(&ts64);
421+
}
413422
put_clock_desc(&cd);
414423
}
415424

416425
static int pc_timer_settime(struct k_itimer *kit, int flags,
417426
struct itimerspec *ts, struct itimerspec *old)
418427
{
428+
struct itimerspec64 ts64 = itimerspec_to_itimerspec64(ts);
419429
clockid_t id = kit->it_clock;
420430
struct posix_clock_desc cd;
431+
struct itimerspec64 old64;
421432
int err;
422433

423434
err = get_clock_desc(id, &cd);
424435
if (err)
425436
return err;
426437

427-
if (cd.clk->ops.timer_settime)
428-
err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old);
438+
if (cd.clk->ops.timer_settime) {
439+
err = cd.clk->ops.timer_settime(cd.clk, kit, flags, &ts64, &old64);
440+
if (old)
441+
*old = itimerspec64_to_itimerspec(&old64);
442+
}
429443
else
430444
err = -EOPNOTSUPP;
431445

0 commit comments

Comments
 (0)