Skip to content

Commit d2e3e0c

Browse files
deepa-hubKAGA-KOKO
authored andcommitted
time: Change k_clock clock_getres() to use timespec64
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. 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 completely. 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-5-git-send-email-deepa.kernel@gmail.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 3c9c12f commit d2e3e0c

6 files changed

Lines changed: 15 additions & 16 deletions

File tree

‎drivers/char/mmtimer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
765765
return err;
766766
}
767767

768-
static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
768+
static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
769769
{
770770
tp->tv_sec = 0;
771771
tp->tv_nsec = sgi_clock_period;

‎include/linux/posix-timers.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct k_itimer {
8787
};
8888

8989
struct k_clock {
90-
int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
90+
int (*clock_getres) (const clockid_t which_clock, struct timespec64 *tp);
9191
int (*clock_set) (const clockid_t which_clock,
9292
const struct timespec *tp);
9393
int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp);

‎kernel/time/alarmtimer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
541541
*
542542
* Returns the granularity of underlying alarm base clock
543543
*/
544-
static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
544+
static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
545545
{
546546
if (!alarmtimer_get_rtcdev())
547547
return -EINVAL;

‎kernel/time/posix-clock.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct timespec64 *ts)
316316
return err;
317317
}
318318

319-
static int pc_clock_getres(clockid_t id, struct timespec *ts)
319+
static int pc_clock_getres(clockid_t id, struct timespec64 *ts)
320320
{
321321
struct posix_clock_desc cd;
322-
struct timespec64 ts64;
323322
int err;
324323

325324
err = get_clock_desc(id, &cd);
326325
if (err)
327326
return err;
328327

329-
if (cd.clk->ops.clock_getres) {
330-
err = cd.clk->ops.clock_getres(cd.clk, &ts64);
331-
*ts = timespec64_to_timespec(ts64);
332-
}
328+
if (cd.clk->ops.clock_getres)
329+
err = cd.clk->ops.clock_getres(cd.clk, ts);
333330
else
334331
err = -EOPNOTSUPP;
335332

‎kernel/time/posix-cpu-timers.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static inline u64 virt_ticks(struct task_struct *p)
116116
}
117117

118118
static int
119-
posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
119+
posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
120120
{
121121
int error = check_clock(which_clock);
122122
if (!error) {
@@ -1369,7 +1369,7 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
13691369
#define THREAD_CLOCK MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
13701370

13711371
static int process_cpu_clock_getres(const clockid_t which_clock,
1372-
struct timespec *tp)
1372+
struct timespec64 *tp)
13731373
{
13741374
return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
13751375
}
@@ -1394,7 +1394,7 @@ static long process_cpu_nsleep_restart(struct restart_block *restart_block)
13941394
return -EINVAL;
13951395
}
13961396
static int thread_cpu_clock_getres(const clockid_t which_clock,
1397-
struct timespec *tp)
1397+
struct timespec64 *tp)
13981398
{
13991399
return posix_cpu_clock_getres(THREAD_CLOCK, tp);
14001400
}

‎kernel/time/posix-timers.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
258258
return 0;
259259
}
260260

261-
static int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
261+
static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 *tp)
262262
{
263-
*tp = ktime_to_timespec(KTIME_LOW_RES);
263+
*tp = ktime_to_timespec64(KTIME_LOW_RES);
264264
return 0;
265265
}
266266

@@ -276,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
276276
return 0;
277277
}
278278

279-
static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec *tp)
279+
static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp)
280280
{
281281
tp->tv_sec = 0;
282282
tp->tv_nsec = hrtimer_resolution;
@@ -1075,13 +1075,15 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
10751075
struct timespec __user *, tp)
10761076
{
10771077
struct k_clock *kc = clockid_to_kclock(which_clock);
1078+
struct timespec64 rtn_tp64;
10781079
struct timespec rtn_tp;
10791080
int error;
10801081

10811082
if (!kc)
10821083
return -EINVAL;
10831084

1084-
error = kc->clock_getres(which_clock, &rtn_tp);
1085+
error = kc->clock_getres(which_clock, &rtn_tp64);
1086+
rtn_tp = timespec64_to_timespec(rtn_tp64);
10851087

10861088
if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
10871089
error = -EFAULT;

0 commit comments

Comments
 (0)