All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces
@ 2015-01-22  2:31 Xunlei Pang
  2015-01-22  2:31 ` [PATCH 2/5] drivers/rtc/rtc-dev.c: " Xunlei Pang
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Xunlei Pang @ 2015-01-22  2:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: rtc-linux, Thomas Gleixner, Alessandro Zummo, John Stultz,
	Arnd Bergmann, Xunlei Pang

Currently, interface.c uses y2038 problematic rtc_tm_to_time()
and rtc_time_to_tm(). So replace them with their corresponding
y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm().

Reviewed-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 drivers/rtc/interface.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index db44df8..c6be2bb 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -76,10 +76,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 		time64_t secs64 = rtc_tm_to_time64(tm);
 		err = rtc->ops->set_mmss64(rtc->dev.parent, secs64);
 	} else if (rtc->ops->set_mmss) {
-		unsigned long secs;
-		err = rtc_tm_to_time(tm, &secs);
-		if (err == 0)
-			err = rtc->ops->set_mmss(rtc->dev.parent, secs);
+		time64_t secs64 = rtc_tm_to_time64(tm);
+		err = rtc->ops->set_mmss(rtc->dev.parent, secs64);
 	} else
 		err = -EINVAL;
 
@@ -110,7 +108,7 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
 
 		err = rtc->ops->read_time(rtc->dev.parent, &old);
 		if (err == 0) {
-			rtc_time_to_tm(secs, &new);
+			rtc_time64_to_tm(secs, &new);
 
 			/*
 			 * avoid writing when we're going to change the day of
@@ -162,7 +160,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	int err;
 	struct rtc_time before, now;
 	int first_time = 1;
-	unsigned long t_now, t_alm;
+	time64_t t_now, t_alm;
 	enum { none, day, month, year } missing = none;
 	unsigned days;
 
@@ -263,8 +261,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	}
 
 	/* with luck, no rollover is needed */
-	rtc_tm_to_time(&now, &t_now);
-	rtc_tm_to_time(&alarm->time, &t_alm);
+	t_now = rtc_tm_to_time64(&now);
+	t_alm = rtc_tm_to_time64(&alarm->time);
 	if (t_now < t_alm)
 		goto done;
 
@@ -278,7 +276,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	case day:
 		dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day");
 		t_alm += 24 * 60 * 60;
-		rtc_time_to_tm(t_alm, &alarm->time);
+		rtc_time64_to_tm(t_alm, &alarm->time);
 		break;
 
 	/* Month rollover ... if it's the 31th, an alarm on the 3rd will
@@ -351,19 +349,19 @@ EXPORT_SYMBOL_GPL(rtc_read_alarm);
 static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 {
 	struct rtc_time tm;
-	long now, scheduled;
+	time64_t now, scheduled;
 	int err;
 
 	err = rtc_valid_tm(&alarm->time);
 	if (err)
 		return err;
-	rtc_tm_to_time(&alarm->time, &scheduled);
+	scheduled = rtc_tm_to_time64(&alarm->time);
 
 	/* Make sure we're not setting alarms in the past */
 	err = __rtc_read_time(rtc, &tm);
 	if (err)
 		return err;
-	rtc_tm_to_time(&tm, &now);
+	now = rtc_tm_to_time64(&tm);
 	if (scheduled <= now)
 		return -ETIME;
 	/*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] drivers/rtc/rtc-dev.c: Update code to use y2038-safe time interfaces
  2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
@ 2015-01-22  2:31 ` Xunlei Pang
  2015-01-22  2:31 ` [PATCH 3/5] rtc: Modify rtc_hctosys() to address y2038 issues Xunlei Pang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Xunlei Pang @ 2015-01-22  2:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: rtc-linux, Thomas Gleixner, Alessandro Zummo, John Stultz,
	Arnd Bergmann, Xunlei Pang

Currently, rtc-dev.c uses y2038 problematic rtc_tm_to_time()
and rtc_time_to_tm(). So replace them with their corresponding
y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm().

Reviewed-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 drivers/rtc/rtc-dev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index d049393..799c34b 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -304,12 +304,12 @@ static long rtc_dev_ioctl(struct file *file,
 		 * Not supported here.
 		 */
 		{
-			unsigned long now, then;
+			time64_t now, then;
 
 			err = rtc_read_time(rtc, &tm);
 			if (err < 0)
 				return err;
-			rtc_tm_to_time(&tm, &now);
+			now = rtc_tm_to_time64(&tm);
 
 			alarm.time.tm_mday = tm.tm_mday;
 			alarm.time.tm_mon = tm.tm_mon;
@@ -317,11 +317,11 @@ static long rtc_dev_ioctl(struct file *file,
 			err  = rtc_valid_tm(&alarm.time);
 			if (err < 0)
 				return err;
-			rtc_tm_to_time(&alarm.time, &then);
+			then = rtc_tm_to_time64(&alarm.time);
 
 			/* alarm may need to wrap into tomorrow */
 			if (then < now) {
-				rtc_time_to_tm(now + 24 * 60 * 60, &tm);
+				rtc_time64_to_tm(now + 24 * 60 * 60, &tm);
 				alarm.time.tm_mday = tm.tm_mday;
 				alarm.time.tm_mon = tm.tm_mon;
 				alarm.time.tm_year = tm.tm_year;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] rtc: Modify rtc_hctosys() to address y2038 issues
  2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
  2015-01-22  2:31 ` [PATCH 2/5] drivers/rtc/rtc-dev.c: " Xunlei Pang
@ 2015-01-22  2:31 ` Xunlei Pang
  2015-01-22  2:31 ` [PATCH 4/5] rtc: Remove redundant rtc_valid_tm() from rtc_hctosys() Xunlei Pang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Xunlei Pang @ 2015-01-22  2:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: rtc-linux, Thomas Gleixner, Alessandro Zummo, John Stultz,
	Arnd Bergmann, Xunlei Pang

rtc_hctosys() has a number of y2038 issues.

This patch resolves them by:
- Replace rtc_tm_to_time() with y2038-safe rtc_tm_to_time64()
- Replace do_settimeofday() with y2038-safe do_settimeofday64()

After this patch, it should not have any remaining y2038 issues.

Reviewed-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 drivers/rtc/hctosys.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index 4aa60d7..2153b52 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -26,7 +26,7 @@ static int __init rtc_hctosys(void)
 {
 	int err = -ENODEV;
 	struct rtc_time tm;
-	struct timespec tv = {
+	struct timespec64 tv64 = {
 		.tv_nsec = NSEC_PER_SEC >> 1,
 	};
 	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
@@ -52,16 +52,16 @@ static int __init rtc_hctosys(void)
 		goto err_invalid;
 	}
 
-	rtc_tm_to_time(&tm, &tv.tv_sec);
+	tv64.tv_sec = rtc_tm_to_time64(&tm);
 
-	err = do_settimeofday(&tv);
+	err = do_settimeofday64(&tv64);
 
 	dev_info(rtc->dev.parent,
 		"setting system clock to "
-		"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
+		"%d-%02d-%02d %02d:%02d:%02d UTC (%lld)\n",
 		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
 		tm.tm_hour, tm.tm_min, tm.tm_sec,
-		(unsigned int) tv.tv_sec);
+		(long long) tv64.tv_sec);
 
 err_invalid:
 err_read:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] rtc: Remove redundant rtc_valid_tm() from rtc_hctosys()
  2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
  2015-01-22  2:31 ` [PATCH 2/5] drivers/rtc/rtc-dev.c: " Xunlei Pang
  2015-01-22  2:31 ` [PATCH 3/5] rtc: Modify rtc_hctosys() to address y2038 issues Xunlei Pang
@ 2015-01-22  2:31 ` Xunlei Pang
  2015-01-22  2:31 ` [PATCH 5/5] rtc: Convert rtc_set_ntp_time() to use timespec64 Xunlei Pang
  2015-01-22  7:25 ` [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces John Stultz
  4 siblings, 0 replies; 6+ messages in thread
From: Xunlei Pang @ 2015-01-22  2:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: rtc-linux, Thomas Gleixner, Alessandro Zummo, John Stultz,
	Arnd Bergmann, Xunlei Pang

rtc_read_time() has already judged valid tm by rtc_valid_tm(),
so just remove it.

Reviewed-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 drivers/rtc/hctosys.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index 2153b52..6c719f2 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -45,13 +45,6 @@ static int __init rtc_hctosys(void)
 
 	}
 
-	err = rtc_valid_tm(&tm);
-	if (err) {
-		dev_err(rtc->dev.parent,
-			"hctosys: invalid date/time\n");
-		goto err_invalid;
-	}
-
 	tv64.tv_sec = rtc_tm_to_time64(&tm);
 
 	err = do_settimeofday64(&tv64);
@@ -63,7 +56,6 @@ static int __init rtc_hctosys(void)
 		tm.tm_hour, tm.tm_min, tm.tm_sec,
 		(long long) tv64.tv_sec);
 
-err_invalid:
 err_read:
 	rtc_class_close(rtc);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] rtc: Convert rtc_set_ntp_time() to use timespec64
  2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
                   ` (2 preceding siblings ...)
  2015-01-22  2:31 ` [PATCH 4/5] rtc: Remove redundant rtc_valid_tm() from rtc_hctosys() Xunlei Pang
@ 2015-01-22  2:31 ` Xunlei Pang
  2015-01-22  7:25 ` [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces John Stultz
  4 siblings, 0 replies; 6+ messages in thread
From: Xunlei Pang @ 2015-01-22  2:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: rtc-linux, Thomas Gleixner, Alessandro Zummo, John Stultz,
	Arnd Bergmann, Xunlei Pang

rtc_set_ntp_time() uses timespec which is y2038-unsafe,
so modify to use timespec64 which is y2038-safe, then
replace rtc_time_to_tm() with rtc_time64_to_tm().

Also adjust all its call sites(only NTP uses it) accordingly.

Reviewed-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 drivers/rtc/systohc.c | 6 +++---
 include/linux/rtc.h   | 2 +-
 kernel/time/ntp.c     | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c
index e34a07b..22bbe2e 100644
--- a/drivers/rtc/systohc.c
+++ b/drivers/rtc/systohc.c
@@ -20,16 +20,16 @@
  *
  * If temporary failure is indicated the caller should try again 'soon'
  */
-int rtc_set_ntp_time(struct timespec now)
+int rtc_set_ntp_time(struct timespec64 now)
 {
 	struct rtc_device *rtc;
 	struct rtc_time tm;
 	int err = -ENODEV;
 
 	if (now.tv_nsec < (NSEC_PER_SEC >> 1))
-		rtc_time_to_tm(now.tv_sec, &tm);
+		rtc_time64_to_tm(now.tv_sec, &tm);
 	else
-		rtc_time_to_tm(now.tv_sec + 1, &tm);
+		rtc_time64_to_tm(now.tv_sec + 1, &tm);
 
 	rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
 	if (rtc) {
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 29093da..8dcf682 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -162,7 +162,7 @@ extern void devm_rtc_device_unregister(struct device *dev,
 extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
 extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
 extern int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs);
-extern int rtc_set_ntp_time(struct timespec now);
+extern int rtc_set_ntp_time(struct timespec64 now);
 int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm);
 extern int rtc_read_alarm(struct rtc_device *rtc,
 			struct rtc_wkalrm *alrm);
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 87a346f..183dfe2 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -488,13 +488,13 @@ static void sync_cmos_clock(struct work_struct *work)
 
 	getnstimeofday64(&now);
 	if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) {
-		struct timespec adjust = timespec64_to_timespec(now);
+		struct timespec64 adjust = now;
 
 		fail = -ENODEV;
 		if (persistent_clock_is_local)
 			adjust.tv_sec -= (sys_tz.tz_minuteswest * 60);
 #ifdef CONFIG_GENERIC_CMOS_UPDATE
-		fail = update_persistent_clock(adjust);
+		fail = update_persistent_clock(timespec64_to_timespec(adjust));
 #endif
 #ifdef CONFIG_RTC_SYSTOHC
 		if (fail == -ENODEV)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces
  2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
                   ` (3 preceding siblings ...)
  2015-01-22  2:31 ` [PATCH 5/5] rtc: Convert rtc_set_ntp_time() to use timespec64 Xunlei Pang
@ 2015-01-22  7:25 ` John Stultz
  4 siblings, 0 replies; 6+ messages in thread
From: John Stultz @ 2015-01-22  7:25 UTC (permalink / raw)
  To: Xunlei Pang
  Cc: lkml, rtc-linux, Thomas Gleixner, Alessandro Zummo, Arnd Bergmann

On Wed, Jan 21, 2015 at 6:31 PM, Xunlei Pang <pang.xunlei@linaro.org> wrote:
> Currently, interface.c uses y2038 problematic rtc_tm_to_time()
> and rtc_time_to_tm(). So replace them with their corresponding
> y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm().


Ok, I've queued this set of 5 (with a few minor tweaks). If I don't
hear any other objections I'll submit them in with my 3.20 set.

You're other patchset focusing on the setmms64 change and the hardware
specific rtc drivers should probably go in via Alessandro (unless
Alessandro suggests otherwise).  There may be slight fuzz in -next
between the first patch here and that patchset (which I hit), but it
should be easy enough to resolve.

thanks
-john

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-22  7:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-22  2:31 [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces Xunlei Pang
2015-01-22  2:31 ` [PATCH 2/5] drivers/rtc/rtc-dev.c: " Xunlei Pang
2015-01-22  2:31 ` [PATCH 3/5] rtc: Modify rtc_hctosys() to address y2038 issues Xunlei Pang
2015-01-22  2:31 ` [PATCH 4/5] rtc: Remove redundant rtc_valid_tm() from rtc_hctosys() Xunlei Pang
2015-01-22  2:31 ` [PATCH 5/5] rtc: Convert rtc_set_ntp_time() to use timespec64 Xunlei Pang
2015-01-22  7:25 ` [PATCH 1/5] drivers/rtc/interface.c: Update code to use y2038-safe time interfaces John Stultz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.