From: Baolin Wang <baolin.wang@linaro.org>
To: tglx@linutronix.de
Cc: arnd@arndb.de, john.stultz@linaro.org, hofrat@osadl.org,
ahh@google.com, linux-kernel@vger.kernel.org,
baolin.wang@linaro.org, y2038@lists.linaro.org
Subject: [PATCH v2 5/5] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
Date: Wed, 29 Jul 2015 20:18:31 +0800 [thread overview]
Message-ID: <cfde683815badbf7cc79193d74d5ec310f00cf83.1438170155.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <cover.1438170154.git.baolin.wang@linaro.org>
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
prev parent reply other threads:[~2015-07-29 12:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-30 1:44 [PATCH v2 0/5] Introduce 64bit accessors and structures required to address y2038 issues in the posix_clock subsystem Baolin Wang
2015-07-29 11:58 ` [PATCH v2 1/5] time: Introduce struct itimerspec64 Baolin Wang
2015-07-29 12:09 ` [PATCH v2 2/5] timekeeping: Introduce current_kernel_time64() Baolin Wang
2015-07-29 12:13 ` [PATCH v2 3/5] security: Introduce security_settime64() Baolin Wang
2015-07-30 8:23 ` James Morris
2016-04-18 16:01 ` [RESEND PATCH " Arnd Bergmann
2016-04-18 16:31 ` Mark Brown
2016-04-19 1:57 ` Baolin Wang
2016-04-18 16:54 ` John Stultz
2016-04-18 17:04 ` Kees Cook
2016-04-19 19:59 ` Serge E. Hallyn
2016-04-19 2:02 ` Baolin Wang
2015-07-29 12:16 ` [PATCH v2 4/5] time: Introduce do_sys_settimeofday64() Baolin Wang
2015-07-29 12:18 ` Baolin Wang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfde683815badbf7cc79193d74d5ec310f00cf83.1438170155.git.baolin.wang@linaro.org \
--to=baolin.wang@linaro.org \
--cc=ahh@google.com \
--cc=arnd@arndb.de \
--cc=hofrat@osadl.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=y2038@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).