This is mostly a search&replace of all uses of timex in the kernel,
to allow using the new definition. Architectures that do not
set CONFIG_COMPAT_TIME will still see the old definition, and nothing
changes for them.

Signed-off-by: Arnd Bergmann <[email protected]>
---
 arch/alpha/kernel/osf_sys.c  |  2 +-
 arch/s390/kernel/time.c      |  2 +-
 drivers/ptp/ptp_clock.c      |  2 +-
 include/linux/compat_time.h  |  6 +++---
 include/linux/posix-clock.h  |  2 +-
 include/linux/posix-timers.h |  2 +-
 include/linux/syscalls.h     |  6 +++---
 include/linux/timex.h        |  6 +++++-
 include/uapi/linux/timex.h   |  3 ++-
 kernel/compat.c              |  8 ++++----
 kernel/time/ntp.c            | 16 ++++++++--------
 kernel/time/ntp_internal.h   |  4 ++--
 kernel/time/posix-clock.c    |  2 +-
 kernel/time/posix-timers.c   | 26 ++++++++++++++------------
 kernel/time/time.c           |  8 ++++----
 kernel/time/timekeeping.c    |  2 +-
 16 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 04368e8129b7..678ba1b531e4 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1269,7 +1269,7 @@ struct timex32 {
 
 SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
 {
-        struct timex txc;
+        struct __kernel_timex txc;
        int ret;
 
        /* copy relevant bits of struct timex. */
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index 170ddd2018b3..7941cc48a114 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -305,7 +305,7 @@ static unsigned long long adjust_time(unsigned long long 
old,
                                      unsigned long long delay)
 {
        unsigned long long delta, ticks;
-       struct timex adjust;
+       struct __kernel_timex adjust;
 
        if (clock > old) {
                /* It is later than we thought. */
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 2e481b9e8ea5..b799fb4c4ef6 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -124,7 +124,7 @@ static int ptp_clock_gettime(struct posix_clock *pc, struct 
timespec *tp)
        return err;
 }
 
-static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
+static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx)
 {
        struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
        struct ptp_clock_info *ops;
diff --git a/include/linux/compat_time.h b/include/linux/compat_time.h
index afaa1ca7986d..baa4a96a14d6 100644
--- a/include/linux/compat_time.h
+++ b/include/linux/compat_time.h
@@ -121,9 +121,9 @@ extern int compat_put_timeval(const struct timeval *, void 
__user *);
 extern int compat_get_timespec64(struct timespec64 *ts, const void __user 
*uts);
 extern int compat_put_timespec64(const struct timespec64 *ts, void __user 
*uts);
 struct compat_timex;
-struct timex;
-extern int compat_get_timex(struct timex *txc, struct compat_timex __user 
*utp);
-extern int compat_put_timex(struct compat_timex __user *utp, struct timex 
*txc);
+struct __kernel_timex;
+extern int compat_get_timex(struct __kernel_timex *txc, struct compat_timex 
__user *utp);
+extern int compat_put_timex(struct compat_timex __user *utp, struct 
__kernel_timex *txc);
 
 /*
  * This function convert a timespec if necessary and returns a *user
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 34c4498b800f..99162e319dde 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -57,7 +57,7 @@ struct posix_clock;
 struct posix_clock_operations {
        struct module *owner;
 
-       int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
+       int  (*clock_adjtime)(struct posix_clock *pc, struct __kernel_timex 
*tx);
 
        int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
 
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2d676be022e4..28637f929458 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -101,7 +101,7 @@ struct k_clock {
        int (*clock_set) (const clockid_t which_clock,
                          const struct timespec *tp);
        int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
-       int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
+       int (*clock_adj) (const clockid_t which_clock, struct __kernel_timex 
*tx);
        int (*timer_create) (struct k_itimer *timer);
        int (*nsleep) (const clockid_t which_clock, int flags,
                       struct timespec *, struct timespec __user *);
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index c7b1ea2e421a..eb58a31979fc 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -49,7 +49,7 @@ struct __sysctl_args;
 struct sysinfo;
 struct timespec;
 struct timeval;
-struct timex;
+struct __kernel_timex;
 struct timezone;
 struct tms;
 struct utimbuf;
@@ -211,7 +211,7 @@ asmlinkage long sys_gettimeofday(struct timeval __user *tv,
                                struct timezone __user *tz);
 asmlinkage long sys_settimeofday(struct timeval __user *tv,
                                struct timezone __user *tz);
-asmlinkage long sys_adjtimex(struct timex __user *txc_p);
+asmlinkage long sys_adjtimex(struct __kernel_timex __user *txc_p);
 
 asmlinkage long sys_times(struct tms __user *tbuf);
 
@@ -275,7 +275,7 @@ asmlinkage long sys_clock_settime(clockid_t which_clock,
 asmlinkage long sys_clock_gettime(clockid_t which_clock,
                                struct timespec __user *tp);
 asmlinkage long sys_clock_adjtime(clockid_t which_clock,
-                               struct timex __user *tx);
+                               struct __kernel_timex __user *tx);
 asmlinkage long sys_clock_getres(clockid_t which_clock,
                                struct timespec __user *tp);
 asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 9d3f1a5b6178..d7374006b054 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -53,6 +53,10 @@
 #ifndef _LINUX_TIMEX_H
 #define _LINUX_TIMEX_H
 
+#ifndef CONFIG_COMPAT_TIME
+#define __kernel_timex timex
+#endif
+
 #include <uapi/linux/timex.h>
 
 #define ADJ_ADJTIME            0x8000  /* switch between adjtime/adjtimex 
modes */
@@ -151,7 +155,7 @@ extern unsigned long tick_nsec;             /* SHIFTED_HZ 
period (nsec) */
 #define NTP_INTERVAL_FREQ  (HZ)
 #define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)
 
-extern int do_adjtimex(struct timex *);
+extern int do_adjtimex(struct __kernel_timex *);
 extern void hardpps(const struct timespec *, const struct timespec *);
 
 int read_current_timer(unsigned long *timer_val);
diff --git a/include/uapi/linux/timex.h b/include/uapi/linux/timex.h
index 80c429ecdf4e..9b131f107ada 100644
--- a/include/uapi/linux/timex.h
+++ b/include/uapi/linux/timex.h
@@ -92,7 +92,7 @@ struct timex {
        int  :32; int  :32; int  :32;
 };
 
-
+#ifndef __kernel_timex
 /*
  * __kernel_timex is the new structure that uses the same layout
  * as timex on 64-bit machines
@@ -135,6 +135,7 @@ struct __kernel_timex {
        int  :32; int  :32; int  :32; int  :32;
        int  :32; int  :32; int  :32;
 };
+#endif
 
 /*
  * Mode codes (timex.mode)
diff --git a/kernel/compat.c b/kernel/compat.c
index 22a20bd37a73..1837c8ec79cf 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -33,9 +33,9 @@
 #include <asm/uaccess.h>
 
 #ifdef CONFIG_COMPAT_TIME
-int compat_get_timex(struct timex *txc, struct compat_timex __user *utp)
+int compat_get_timex(struct __kernel_timex *txc, struct compat_timex __user 
*utp)
 {
-       memset(txc, 0, sizeof(struct timex));
+       memset(txc, 0, sizeof(struct __kernel_timex));
 
        if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
                        __get_user(txc->modes, &utp->modes) ||
@@ -63,7 +63,7 @@ int compat_get_timex(struct timex *txc, struct compat_timex 
__user *utp)
        return 0;
 }
 
-int compat_put_timex(struct compat_timex __user *utp, struct timex *txc)
+int compat_put_timex(struct compat_timex __user *utp, struct __kernel_timex 
*txc)
 {
        if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
                        __put_user(txc->modes, &utp->modes) ||
@@ -1011,7 +1011,7 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, 
tptr)
 
 COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp)
 {
-       struct timex txc;
+       struct __kernel_timex txc;
        int err, ret;
 
        err = compat_get_timex(&txc, utp);
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 7a681003001c..eefffbec227b 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -181,7 +181,7 @@ static inline int is_error_status(int status)
                        && (status & (STA_PPSWANDER|STA_PPSERROR)));
 }
 
-static inline void pps_fill_timex(struct timex *txc)
+static inline void pps_fill_timex(struct __kernel_timex *txc)
 {
        txc->ppsfreq       = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) *
                                         PPM_SCALE_INV, NTP_SCALE_SHIFT);
@@ -213,7 +213,7 @@ static inline int is_error_status(int status)
        return status & (STA_UNSYNC|STA_CLOCKERR);
 }
 
-static inline void pps_fill_timex(struct timex *txc)
+static inline void pps_fill_timex(struct __kernel_timex *txc)
 {
        /* PPS is not implemented, so these are zero */
        txc->ppsfreq       = 0;
@@ -542,7 +542,7 @@ void ntp_notify_cmos_timer(void) { }
 /*
  * Propagate a new txc->status value into the NTP state:
  */
-static inline void process_adj_status(struct timex *txc, struct timespec64 *ts)
+static inline void process_adj_status(struct __kernel_timex *txc, struct 
timespec64 *ts)
 {
        if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
                time_state = TIME_OK;
@@ -564,7 +564,7 @@ static inline void process_adj_status(struct timex *txc, 
struct timespec64 *ts)
 }
 
 
-static inline void process_adjtimex_modes(struct timex *txc,
+static inline void process_adjtimex_modes(struct __kernel_timex *txc,
                                                struct timespec64 *ts,
                                                s32 *time_tai)
 {
@@ -617,7 +617,7 @@ static inline void process_adjtimex_modes(struct timex *txc,
 /**
  * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex
  */
-int ntp_validate_timex(struct timex *txc)
+int ntp_validate_timex(struct __kernel_timex *txc)
 {
        if (txc->modes & ADJ_ADJTIME) {
                /* singleshot must not be used with any other mode bits */
@@ -662,7 +662,7 @@ int ntp_validate_timex(struct timex *txc)
  * adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
-int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai)
+int __do_adjtimex(struct __kernel_timex *txc, struct timespec64 *ts, s32 
*time_tai)
 {
        int result;
 
@@ -684,7 +684,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, 
s32 *time_tai)
                txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
                                  NTP_SCALE_SHIFT);
                if (!(time_status & STA_NANO))
-                       txc->offset /= NSEC_PER_USEC;
+                       txc->offset = (long)txc->offset / NSEC_PER_USEC;
        }
 
        result = time_state;    /* mostly `TIME_OK' */
@@ -709,7 +709,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, 
s32 *time_tai)
        txc->time.tv_sec = (time_t)ts->tv_sec;
        txc->time.tv_usec = ts->tv_nsec;
        if (!(time_status & STA_NANO))
-               txc->time.tv_usec /= NSEC_PER_USEC;
+               txc->time.tv_usec = (long)txc->time.tv_usec / NSEC_PER_USEC;
 
        return result;
 }
diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h
index bbd102ad9df7..fdee75fd1a49 100644
--- a/kernel/time/ntp_internal.h
+++ b/kernel/time/ntp_internal.h
@@ -6,7 +6,7 @@ extern void ntp_clear(void);
 /* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */
 extern u64 ntp_tick_length(void);
 extern int second_overflow(unsigned long secs);
-extern int ntp_validate_timex(struct timex *);
-extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *);
+extern int ntp_validate_timex(struct __kernel_timex *);
+extern int __do_adjtimex(struct __kernel_timex *, struct timespec64 *, s32 *);
 extern void __hardpps(const struct timespec *, const struct timespec *);
 #endif /* _LINUX_NTP_INTERNAL_H */
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index ce033c7aa2e8..4724d5926d4b 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -273,7 +273,7 @@ static void put_clock_desc(struct posix_clock_desc *cd)
        fput(cd->fp);
 }
 
-static int pc_clock_adjtime(clockid_t id, struct timex *tx)
+static int pc_clock_adjtime(clockid_t id, struct __kernel_timex *tx)
 {
        struct posix_clock_desc cd;
        int err;
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 4c0d43c7c015..0b4ae6ad825a 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -218,7 +218,7 @@ static int posix_clock_realtime_set(const clockid_t 
which_clock,
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
-                                   struct timex *t)
+                                   struct __kernel_timex *t)
 {
        return do_adjtimex(t);
 }
@@ -1070,22 +1070,28 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, 
which_clock,
        return error;
 }
 
-SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
-               struct timex __user *, utx)
+static int clock_adjtime(clockid_t which_clock, struct __kernel_timex *ktx)
 {
        struct k_clock *kc = clockid_to_kclock(which_clock);
-       struct timex ktx;
-       int err;
 
        if (!kc)
                return -EINVAL;
        if (!kc->clock_adj)
                return -EOPNOTSUPP;
 
+       return kc->clock_adj(which_clock, ktx);
+}
+
+SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
+               struct __kernel_timex __user *, utx)
+{
+       struct __kernel_timex ktx;
+       int err;
+
        if (copy_from_user(&ktx, utx, sizeof(ktx)))
                return -EFAULT;
 
-       err = kc->clock_adj(which_clock, &ktx);
+       err = clock_adjtime(which_clock, &ktx);
 
        if (err >= 0 && copy_to_user(utx, &ktx, sizeof(ktx)))
                return -EFAULT;
@@ -1236,18 +1242,14 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, 
which_clock,
 COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
                       struct compat_timex __user *, utp)
 {
-       struct timex txc;
-       mm_segment_t oldfs;
+       struct __kernel_timex txc;
        int err, ret;
 
        err = compat_get_timex(&txc, utp);
        if (err)
                return err;
 
-       oldfs = get_fs();
-       set_fs(KERNEL_DS);
-       ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
-       set_fs(oldfs);
+       ret = clock_adjtime(which_clock, &txc);
 
        err = compat_put_timex(utp, &txc);
        if (err)
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 4be28cec4c20..0310e654c042 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -213,19 +213,19 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
        return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
-SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
+SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p)
 {
-       struct timex txc;               /* Local copy of parameter */
+       struct __kernel_timex txc;              /* Local copy of parameter */
        int ret;
 
        /* Copy the user data space into the kernel copy
         * structure. But bear in mind that the structures
         * may change
         */
-       if(copy_from_user(&txc, txc_p, sizeof(struct timex)))
+       if(copy_from_user(&txc, txc_p, sizeof(struct __kernel_timex)))
                return -EFAULT;
        ret = do_adjtimex(&txc);
-       return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret;
+       return copy_to_user(txc_p, &txc, sizeof(struct __kernel_timex)) ? 
-EFAULT : ret;
 }
 
 /**
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 946acb72179f..e363752f0ccc 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1991,7 +1991,7 @@ ktime_t ktime_get_update_offsets_now(ktime_t *offs_real, 
ktime_t *offs_boot,
 /**
  * do_adjtimex() - Accessor function to NTP __do_adjtimex function
  */
-int do_adjtimex(struct timex *txc)
+int do_adjtimex(struct __kernel_timex *txc)
 {
        struct timekeeper *tk = &tk_core.timekeeper;
        unsigned long flags;
-- 
2.1.0.rc2

_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038

Reply via email to