Skip to content

Commit 86d3473

Browse files
wangbaolin719johnstultz-work
authored andcommitted
time: Introduce do_sys_settimeofday64()
The do_sys_settimeofday() function uses a timespec, which is not year 2038 safe on 32bit systems. Thus this patch introduces do_sys_settimeofday64(), which allows us to transition users of do_sys_settimeofday() to using 64bit time types. Cc: Prarit Bhargava <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Signed-off-by: Baolin Wang <[email protected]> [jstultz: Include errno-base.h to avoid build issue on some arches] Signed-off-by: John Stultz <[email protected]>
1 parent 457db29 commit 86d3473

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

include/linux/timekeeping.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _LINUX_TIMEKEEPING_H
22
#define _LINUX_TIMEKEEPING_H
33

4+
#include <asm-generic/errno-base.h>
5+
46
/* Included from linux/ktime.h */
57

68
void timekeeping_init(void);
@@ -11,8 +13,19 @@ extern int timekeeping_suspended;
1113
*/
1214
extern void do_gettimeofday(struct timeval *tv);
1315
extern int do_settimeofday64(const struct timespec64 *ts);
14-
extern int do_sys_settimeofday(const struct timespec *tv,
15-
const struct timezone *tz);
16+
extern int do_sys_settimeofday64(const struct timespec64 *tv,
17+
const struct timezone *tz);
18+
static inline int do_sys_settimeofday(const struct timespec *tv,
19+
const struct timezone *tz)
20+
{
21+
struct timespec64 ts64;
22+
23+
if (!tv)
24+
return -EINVAL;
25+
26+
ts64 = timespec_to_timespec64(*tv);
27+
return do_sys_settimeofday64(&ts64, tz);
28+
}
1629

1730
/*
1831
* Kernel time accessors

kernel/time/time.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ static inline void warp_clock(void)
160160
* various programs will get confused when the clock gets warped.
161161
*/
162162

163-
int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
163+
int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz)
164164
{
165165
static int firsttime = 1;
166166
int error = 0;
167167

168-
if (tv && !timespec_valid(tv))
168+
if (tv && !timespec64_valid(tv))
169169
return -EINVAL;
170170

171-
error = security_settime(tv, tz);
171+
error = security_settime64(tv, tz);
172172
if (error)
173173
return error;
174174

@@ -186,7 +186,7 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
186186
}
187187
}
188188
if (tv)
189-
return do_settimeofday(tv);
189+
return do_settimeofday64(tv);
190190
return 0;
191191
}
192192

0 commit comments

Comments
 (0)