Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1184296

[PATCH 5/6] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()

From Baolin Wang <baolin.wang@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 5/6] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
Date 2015-07-15 08:10 +0200
Message-ID <pMo3g-7ko-9@gated-at.bofh.it> (permalink)
References <pMnJV-6IC-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


The conversion between struct timespec and jiffies is not year 2038
safe on 32bit systems. Introduce timespec64_to_jiffies() and
jiffies_to_timespec64() functions which use struct timespec64 to
make it ready for 2038 issue.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/jiffies.h |   22 +++++++++++++++++++---
 kernel/time/time.c      |   20 +++++++++++++-------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 535fd3b..bf96d9f 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -416,9 +416,25 @@ static inline unsigned long usecs_to_jiffies(const unsigned int u)
 	}
 }
 
-extern unsigned long timespec_to_jiffies(const struct timespec *value);
-extern void jiffies_to_timespec(const unsigned long jiffies,
-				struct timespec *value);
+extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
+extern void jiffies_to_timespec64(const unsigned long jiffies,
+				  struct timespec64 *value);
+static inline unsigned long timespec_to_jiffies(const struct timespec *value)
+{
+	struct timespec64 ts = timespec_to_timespec64(*value);
+
+	return timespec64_to_jiffies(&ts);
+}
+
+static inline void jiffies_to_timespec(const unsigned long jiffies,
+				       struct timespec *value)
+{
+	struct timespec64 ts;
+
+	jiffies_to_timespec64(jiffies, &ts);
+	*value = timespec64_to_timespec(ts);
+}
+
 extern unsigned long timeval_to_jiffies(const struct timeval *value);
 extern void jiffies_to_timeval(const unsigned long jiffies,
 			       struct timeval *value);
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5d00da4..6692f5a 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -546,7 +546,7 @@ EXPORT_SYMBOL(__usecs_to_jiffies);
  * value to a scaled second value.
  */
 static unsigned long
-__timespec_to_jiffies(unsigned long sec, long nsec)
+__timespec64_to_jiffies(u64 sec, long nsec)
 {
 	nsec = nsec + TICK_NSEC - 1;
 
@@ -554,22 +554,28 @@ __timespec_to_jiffies(unsigned long sec, long nsec)
 		sec = MAX_SEC_IN_JIFFIES;
 		nsec = 0;
 	}
-	return (((u64)sec * SEC_CONVERSION) +
+	return ((sec * SEC_CONVERSION) +
 		(((u64)nsec * NSEC_CONVERSION) >>
 		 (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
 
 }
 
+static unsigned long
+__timespec_to_jiffies(unsigned long sec, long nsec)
+{
+	return __timespec64_to_jiffies((u64)sec, nsec);
+}
+
 unsigned long
-timespec_to_jiffies(const struct timespec *value)
+timespec64_to_jiffies(const struct timespec64 *value)
 {
-	return __timespec_to_jiffies(value->tv_sec, value->tv_nsec);
+	return __timespec64_to_jiffies(value->tv_sec, value->tv_nsec);
 }
 
-EXPORT_SYMBOL(timespec_to_jiffies);
+EXPORT_SYMBOL(timespec64_to_jiffies);
 
 void
-jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
+jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value)
 {
 	/*
 	 * Convert jiffies to nanoseconds and separate with
@@ -580,7 +586,7 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
 				    NSEC_PER_SEC, &rem);
 	value->tv_nsec = rem;
 }
-EXPORT_SYMBOL(jiffies_to_timespec);
+EXPORT_SYMBOL(jiffies_to_timespec64);
 
 /*
  * We could use a similar algorithm to timespec_to_jiffies (with a
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH 0/6] Introduce 64bit accessors and structures required to address y2038 issues in the posix_clock subsystem Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 07:50 +0200
  [PATCH 2/6] timekeeping: Introduce current_kernel_time64() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:00 +0200
  [PATCH 3/6] security: Introduce security_settime64() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:00 +0200
    Re: [PATCH 3/6] security: Introduce security_settime64() Thomas Gleixner <tglx@linutronix.de> - 2015-07-15 12:30 +0200
      Re: [PATCH 3/6] security: Introduce security_settime64() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 13:40 +0200
  [PATCH 1/6] time: Introduce struct itimerspec64 Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:00 +0200
  [PATCH 4/6] time: Introduce do_sys_settimeofday64() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:10 +0200
  [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:10 +0200
    Re: [PATCH 6/6] cputime: Introduce  cputime_to_timespec64()/timespec64_to_cputime() Thomas Gleixner <tglx@linutronix.de> - 2015-07-15 12:40 +0200
      Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 13:50 +0200
        Re: [PATCH 6/6] cputime: Introduce  cputime_to_timespec64()/timespec64_to_cputime() Thomas Gleixner <tglx@linutronix.de> - 2015-07-15 14:00 +0200
          Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang <baolin.wang@linaro.org> - 2015-07-16 04:30 +0200
            Re: [PATCH 6/6] cputime: Introduce  cputime_to_timespec64()/timespec64_to_cputime() Thomas Gleixner <tglx@linutronix.de> - 2015-07-16 12:50 +0200
              Re: [PATCH 6/6] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang <baolin.wang@linaro.org> - 2015-07-17 10:40 +0200
  [PATCH 5/6] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Baolin Wang <baolin.wang@linaro.org> - 2015-07-15 08:10 +0200

csiph-web