Skip to contentSkip to conversation

Provide y2038/y2106 safe rtc_class_ops.set_mmss64()

RFC PATCH In review Xunlei Pang 7 participants 27 messages Jan 13, 2015 – Jan 16, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Provide y2038/y2106 safe rtc_class_ops.set_mmss64()

From: Xunlei Pang <[email protected]>

This patch series relies on a former patchset[1], it provides y2038/y2106 safe rtc_class_ops.set_mmss64(), and converts some possible users of set_mmss() to use set_mmss64(), in the hope that making these users(i.e. rtc drivers) y2038/y2106 safe.

The first version of this patchset is: [2].

[1] https://lkml.org/lkml/2014/11/18/218
[2] https://lkml.org/lkml/2014/11/27/341

Xunlei Pang (9):
rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement
time: Provide y2106 safe get_seconds() replacement rtc/test: Update driver to address y2038/y2106 issues rtc/ab3100: Update driver to address y2038/y2106 issues rtc/mc13xxx: Update driver to address y2038/y2106 issues rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time rtc/mxc: Convert get_alarm_or_time()/set_alarm_or_time() to use

    time64_t

rtc/mxc: Update driver to address y2038/y2106 issues
alpha: change to use rtc_class_ops's set_mmss64()

 arch/alpha/kernel/rtc.c     |  8 +++----
 drivers/rtc/interface.c     |  9 +++++++-
 drivers/rtc/rtc-ab3100.c    | 55 ++++++++++++++++++++++-----------------------
 drivers/rtc/rtc-mc13xxx.c   | 32 ++++++++++++--------------
 drivers/rtc/rtc-mxc.c       | 55 +++++++++++++++++----------------------------
 drivers/rtc/rtc-test.c      |  8 +++----
 drivers/rtc/systohc.c       |  5 ++++-
 include/linux/rtc.h         |  1 +
 include/linux/timekeeping.h | 10 ++++++++-
 kernel/time/timekeeping.c   |  4 ++--
 10 files changed, 93 insertions(+), 94 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH v2 1/9 rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement

From: Xunlei Pang <[email protected]>

Currently the rtc_class_op's set_mmss() function takes a 32bit second value (on 32bit systems), which is problematic for dates past y2038.

This patch provides a safe version named set_mmss64() using y2038 safe time64_t.

After this patch, set_mmss() is deprecated and all its users will be fixed to use set_mmss64(), it can be removed when having no users.

Cc John Stultz <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 drivers/rtc/interface.c | 9 ++++++++-
 drivers/rtc/systohc.c   | 5 ++++-
 include/linux/rtc.h     | 1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/rtc/interface.c +8 -1
index 45bfc28ee..fca7882 100644
@@ -72,7 +72,12 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 		err = -ENODEV;
 	else if (rtc->ops->set_time)
 		err = rtc->ops->set_time(rtc->dev.parent, tm);
-	else if (rtc->ops->set_mmss) {
+	else if (rtc->ops->set_mmss64) {
+		time64_t secs64;
+
+		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)
@@ -98,6 +103,8 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
 
 	if (!rtc->ops)
 		err = -ENODEV;
+	else if (rtc->ops->set_mmss64)
+		err = rtc->ops->set_mmss64(rtc->dev.parent, secs);
 	else if (rtc->ops->set_mmss)
 		err = rtc->ops->set_mmss(rtc->dev.parent, secs);
 	else if (rtc->ops->read_time && rtc->ops->set_time) {
drivers/rtc/systohc.c +4 -1
index bf3e242..e34a07b 100644
@@ -35,7 +35,10 @@ int rtc_set_ntp_time(struct timespec now)
 	if (rtc) {
 		/* rtc_hctosys exclusively uses UTC, so we call set_time here,
 		 * not set_mmss. */
-		if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss))
+		if (rtc->ops &&
+		    (rtc->ops->set_time ||
+		     rtc->ops->set_mmss64 ||
+		     rtc->ops->set_mmss))
 			err = rtc_set_time(rtc, &tm);
 		rtc_class_close(rtc);
 	}
include/linux/rtc.h +1 -0
index 6d6be09..29093da 100644
@@ -77,6 +77,7 @@ struct rtc_class_ops {
 	int (*read_alarm)(struct device *, struct rtc_wkalrm *);
 	int (*set_alarm)(struct device *, struct rtc_wkalrm *);
 	int (*proc)(struct device *, struct seq_file *);
+	int (*set_mmss64)(struct device *, time64_t secs);
 	int (*set_mmss)(struct device *, unsigned long secs);
 	int (*read_callback)(struct device *, int data);
 	int (*alarm_irq_enable)(struct device *, unsigned int enabled);
Signature · 1 line
1.9.1
#2 lore raw

Re: [RFC PATCH v2 1/9] rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement

drivers/rtc/interface.c int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) · line 78

Quoted 4 lines · On Tue, 13 Jan 2015 23:44:49 +0800 Xunlei Pang <[email protected]> wrote:
drivers/rtc/interface.c +4 -0
+	else if (rtc->ops->set_mmss64) {
+		 ;
+
+		secs64 = rtc_tm_to_time64(tm);

time64_t secs64 = rtc_tm_to_time64(tm);

would do as well. add spaces, variables
and empty lines only when required for readability.

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#3 lore raw

RFC PATCH v2 2/9 time: Provide y2106 safe get_seconds() replacement

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

As part of addressing "y2038 problem" for in-kernel uses, this patch adds safe get_seconds64() using time64_t.

After this patch, get_seconds() is deprecated and all its call sites will be fixed using get_seconds64(), after that it can be removed.

---
 include/linux/timekeeping.h | 10 +++++++++-
 kernel/time/timekeeping.c   |  4 ++--
 2 files changed, 11 insertions(+), 3 deletions(-)
include/linux/timekeeping.h +9 -1
index 9b63d13..384d101 100644
@@ -17,7 +17,7 @@ extern int do_sys_settimeofday(const struct timespec *tv,
 /*
  * Kernel time accessors
  */
-unsigned long get_seconds(void);
+extern time64_t get_seconds64(void);
 struct timespec current_kernel_time(void);
 /* does not take xtime_lock */
 struct timespec __current_kernel_time(void);
@@ -34,6 +34,14 @@ extern time64_t ktime_get_real_seconds(void);
 extern int __getnstimeofday64(struct timespec64 *tv);
 extern void getnstimeofday64(struct timespec64 *tv);
 
+/**
+ * Deprecated. Use get_seconds64().
+ */
+static inline unsigned long get_seconds(void)
+{
+	return (unsigned long)get_seconds64();
+}
+
 #if BITS_PER_LONG == 64
 /**
  * Deprecated. Use do_settimeofday64().
kernel/time/timekeeping.c +2 -2
index 6a93185..ab021a3 100644
@@ -1678,13 +1678,13 @@ void getboottime(struct timespec *ts)
 }
 EXPORT_SYMBOL_GPL(getboottime);
 
-unsigned long get_seconds(void)
+time64_t get_seconds64(void)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
 
 	return tk->xtime_sec;
 }
-EXPORT_SYMBOL(get_seconds);
+EXPORT_SYMBOL(get_seconds64);
 
 struct timespec __current_kernel_time(void)
 {
Signature · 1 line
1.9.1
#4 lore raw

Re: [RFC PATCH v2 2/9] time: Provide y2106 safe get_seconds() replacement

kernel/time/timekeeping.c void getboottime(struct timespec *ts) · line 1687

Quoted 2 lines · On Tue, 13 Jan 2015 23:44:50 +0800 Xunlei Pang <[email protected]> wrote:
kernel/time/timekeeping.c +1 -1
-EXPORT_SYMBOL(get_seconds);
+EXPORT_SYMBOL(get_seconds64);

Please leave get_seconds untouched

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#5 lore raw

Re: [RFC PATCH v2 2/9] time: Provide y2106 safe get_seconds() replacement

Quoted 8 lines · On Tuesday 13 January 2015 17:17:44 Alessandro Zummo wrote:

kernel/time/timekeeping.c void getboottime(struct timespec *ts) · line 1687

Quoted 2 lines · On Tue, 13 Jan 2015 23:44:50 +0800 Xunlei Pang <[email protected]> wrote:
kernel/time/timekeeping.c +1 -1
-EXPORT_SYMBOL(get_seconds);
+EXPORT_SYMBOL(get_seconds64);

Please leave get_seconds untouched

The patch leaves it in place. However, we already have ktime_get_seconds() and ktime_get_real_seconds(). Code that currently uses get_seconds can trivially be converted to the latter.

Arnd

#6 lore raw

Re: [RFC PATCH v2 2/9] time: Provide y2106 safe get_seconds() replacement

In reply to Xunlei Pang
Quoted 7 lines · Xunlei Pang

From: Xunlei Pang <[email protected]>

As part of addressing "y2038 problem" for in-kernel uses, this patch adds safe get_seconds64() using time64_t.

After this patch, get_seconds() is deprecated and all its call sites will be fixed using get_seconds64(), after that it can be removed.

Why another interface?

We already have ktime_get_real_seconds(). That handles 32bit correctly, while your new function does not.

You cannot return a 64bit value unprotected against updates on 32bit, unless you want to implement a RNG.

Thanks,

tglx

#7 lore raw

Re: [RFC PATCH v2 2/9] time: Provide y2106 safe get_seconds() replacement

Quoted 10 lines · Thomas Gleixner
Quoted 7 lines · Xunlei Pang

From: Xunlei Pang <[email protected]>

As part of addressing "y2038 problem" for in-kernel uses, this patch adds safe get_seconds64() using time64_t.

After this patch, get_seconds() is deprecated and all its call sites will be fixed using get_seconds64(), after that it can be removed.

Quoted 7 lines

Why another interface?

We already have ktime_get_real_seconds(). That handles 32bit correctly, while your new function does not.

You cannot return a 64bit value unprotected against updates on 32bit, unless you want to implement a RNG.

Yes, ktime_get_real_seconds() should be used instead.

Thanks,
Xunlei

#8 lore raw

RFC PATCH v2 3/9 rtc/test: Update driver to address y2038/y2106 issues

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Repalce get_seconds() with get_seconds64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change test_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, this driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/rtc-test.c +4 -4
index 8f86fa9..056138b 100644
@@ -30,13 +30,13 @@ static int test_rtc_set_alarm(struct device *dev,
 static int test_rtc_read_time(struct device *dev,
 	struct rtc_time *tm)
 {
-	rtc_time_to_tm(get_seconds(), tm);
+	rtc_time64_to_tm(get_seconds64(), tm);
 	return 0;
 }
 
-static int test_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int test_rtc_set_mmss(struct device *dev, time64_t secs)
 {
-	dev_info(dev, "%s, secs = %lu\n", __func__, secs);
+	dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs);
 	return 0;
 }
 
@@ -60,7 +60,7 @@ static const struct rtc_class_ops test_rtc_ops = {
 	.read_time = test_rtc_read_time,
 	.read_alarm = test_rtc_read_alarm,
 	.set_alarm = test_rtc_set_alarm,
-	.set_mmss = test_rtc_set_mmss,
+	.set_mmss64 = test_rtc_set_mmss,
 	.alarm_irq_enable = test_rtc_alarm_irq_enable,
 };
 
Signature · 1 line
1.9.1
#9 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 4 lines · On Tue, 13 Jan 2015 23:44:51 +0800 Xunlei Pang <[email protected]> wrote:

This patch resolves them by:
- Repalce get_seconds() with get_seconds64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change test_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

so we no more have a non time64 test driver?

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#10 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 9 lines · Alessandro Zummo
Quoted 4 lines · On Tue, 13 Jan 2015 23:44:51 +0800 Xunlei Pang <[email protected]> wrote:

This patch resolves them by:
- Repalce get_seconds() with get_seconds64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change test_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

so we no more have a non time64 test driver?|

Hi Alessandro,

We want to do away with set_mmss() eventually, time64 is the final version, so I think this would be ok.

Thanks,
Xunlei

Quoted 10 lines

--

Best regards,

Alessandro Zummo,
Tower Technologies - Torino, Italy

http://www.towertech.it

#11 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 2 lines · On Wed, 14 Jan 2015 22:56:15 +0800 Xunlei Pang <[email protected]> wrote:

We want to do away with set_mmss() eventually, time64 is the final version, so I think this would be ok.

We'll get rid of set_mmss() from the test driver later on, after everything else has been converted :)

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#12 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 8 lines · Alessandro Zummo
Quoted 2 lines · On Wed, 14 Jan 2015 22:56:15 +0800 Xunlei Pang <[email protected]> wrote:

We want to do away with set_mmss() eventually, time64 is the final version, so I think this would be ok.

We'll get rid of set_mmss() from the test driver later on, after everything else has been converted :)

Ok.

But on the other hand, we will have no test for set_mmss64(), because adding the set_mmss64() will make set_mmss() dysfunctional.

Thanks,
Xunlei

Quoted 10 lines

--

Best regards,

Alessandro Zummo,
Tower Technologies - Torino, Italy

http://www.towertech.it

#13 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 2 lines · On Wed, 14 Jan 2015 23:26:37 +0800 Xunlei Pang <[email protected]> wrote:

But on the other hand, we will have no test for set_mmss64(), because adding the set_mmss64() will make set_mmss() dysfunctional.

add a module parameter

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#14 lore raw

Re: [RFC PATCH v2 3/9] rtc/test: Update driver to address y2038/y2106 issues

Quoted 7 lines · Alessandro Zummo
Quoted 2 lines · On Wed, 14 Jan 2015 23:26:37 +0800 Xunlei Pang <[email protected]> wrote:

But on the other hand, we will have no test for set_mmss64(), because adding the set_mmss64() will make set_mmss() dysfunctional.

add a module parameter

Hi Alessandro,

Thanks for your advice, how about the following one?

---
 drivers/rtc/rtc-test.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/rtc/rtc-test.c +11 -1
index 8f86fa9..3a2da4c 100644
@@ -13,6 +13,10 @@
 #include <linux/rtc.h>
 #include <linux/platform_device.h>
 
+static int test_mmss64;
+module_param(test_mmss64, int, 0644);
+MODULE_PARM_DESC(test_mmss64, "Test struct rtc_class_ops.set_mmss64().");
+
 static struct platform_device *test0 = NULL, *test1 = NULL;
 
 static int test_rtc_read_alarm(struct device *dev,
@@ -30,7 +34,13 @@ static int test_rtc_set_alarm(struct device *dev,
 static int test_rtc_read_time(struct device *dev,
  struct rtc_time *tm)
 {
- rtc_time_to_tm(get_seconds(), tm);
+ rtc_time64_to_tm(ktime_get_real_seconds(), tm);
+ return 0;
+}
+
+static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
+{
+ dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs);
  return 0;
 }
 
@@ -55,7 +65,7 @@ static int test_rtc_alarm_irq_enable(struct device

*dev, unsigned int enable)
return 0;
}

-static const struct rtc_class_ops test_rtc_ops = {
+static struct rtc_class_ops test_rtc_ops = {
.proc = test_rtc_proc,
.read_time = test_rtc_read_time,
.read_alarm = test_rtc_read_alarm,
@@ -101,6 +111,11 @@ static int test_probe(struct platform_device *plat_dev)
int err;
struct rtc_device *rtc;

+ if (test_mmss64) {
+ test_rtc_ops.set_mmss64 = test_rtc_set_mmss64;
+ test_rtc_ops.set_mmss = NULL;
+ }
+
rtc = devm_rtc_device_register(&plat_dev->dev, "test", &test_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {

#15 lore raw

RFC PATCH v2 4/9 rtc/ab3100: Update driver to address y2038/y2106 issues

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_tm_to_time() with rtc_tm_to_time64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change ab3100_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-ab3100.c | 55 ++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)
drivers/rtc/rtc-ab3100.c +27 -28
index 1d0340f..9b725c5 100644
@@ -43,21 +43,21 @@
 /*
  * RTC clock functions and device struct declaration
  */
-static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs)
 {
 	u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2,
 		     AB3100_TI3, AB3100_TI4, AB3100_TI5};
 	unsigned char buf[6];
-	u64 fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2;
+	u64 hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2;
 	int err = 0;
 	int i;
 
-	buf[0] = (fat_time) & 0xFF;
-	buf[1] = (fat_time >> 8) & 0xFF;
-	buf[2] = (fat_time >> 16) & 0xFF;
-	buf[3] = (fat_time >> 24) & 0xFF;
-	buf[4] = (fat_time >> 32) & 0xFF;
-	buf[5] = (fat_time >> 40) & 0xFF;
+	buf[0] = (hw_counter) & 0xFF;
+	buf[1] = (hw_counter >> 8) & 0xFF;
+	buf[2] = (hw_counter >> 16) & 0xFF;
+	buf[3] = (hw_counter >> 24) & 0xFF;
+	buf[4] = (hw_counter >> 32) & 0xFF;
+	buf[5] = (hw_counter >> 40) & 0xFF;
 
 	for (i = 0; i < 6; i++) {
 		err = abx500_set_register_interruptible(dev, 0,
@@ -75,7 +75,7 @@ static int ab3100_rtc_set_mmss(struct device *dev, unsigned long secs)
 
 static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	unsigned long time;
+	time64_t time;
 	u8 rtcval;
 	int err;
 
@@ -88,7 +88,7 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		dev_info(dev, "clock not set (lost power)");
 		return -EINVAL;
 	} else {
-		u64 fat_time;
+		u64 hw_counter;
 		u8 buf[6];
 
 		/* Read out time registers */
@@ -98,22 +98,21 @@ static int ab3100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 		if (err != 0)
 			return err;
 
-		fat_time = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) |
+		hw_counter = ((u64) buf[5] << 40) | ((u64) buf[4] << 32) |
 			((u64) buf[3] << 24) | ((u64) buf[2] << 16) |
 			((u64) buf[1] << 8) | (u64) buf[0];
-		time = (unsigned long) (fat_time /
-					(u64) (AB3100_RTC_CLOCK_RATE * 2));
+		time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2);
 	}
 
-	rtc_time_to_tm(time, tm);
+	rtc_time64_to_tm(time, tm);
 
 	return rtc_valid_tm(tm);
 }
 
 static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
-	unsigned long time;
-	u64 fat_time;
+	time64_t time;
+	u64 hw_counter;
 	u8 buf[6];
 	u8 rtcval;
 	int err;
@@ -134,11 +133,11 @@ static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 						     AB3100_AL0, buf, 4);
 	if (err)
 		return err;
-	fat_time = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) |
+	hw_counter = ((u64) buf[3] << 40) | ((u64) buf[2] << 32) |
 		((u64) buf[1] << 24) | ((u64) buf[0] << 16);
-	time = (unsigned long) (fat_time / (u64) (AB3100_RTC_CLOCK_RATE * 2));
+	time = hw_counter / (u64) (AB3100_RTC_CLOCK_RATE * 2);
 
-	rtc_time_to_tm(time, &alarm->time);
+	rtc_time64_to_tm(time, &alarm->time);
 
 	return rtc_valid_tm(&alarm->time);
 }
@@ -147,17 +146,17 @@ static int ab3100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
 	u8 regs[] = {AB3100_AL0, AB3100_AL1, AB3100_AL2, AB3100_AL3};
 	unsigned char buf[4];
-	unsigned long secs;
-	u64 fat_time;
+	time64_t secs;
+	u64 hw_counter;
 	int err;
 	int i;
 
-	rtc_tm_to_time(&alarm->time, &secs);
-	fat_time = (u64) secs * AB3100_RTC_CLOCK_RATE * 2;
-	buf[0] = (fat_time >> 16) & 0xFF;
-	buf[1] = (fat_time >> 24) & 0xFF;
-	buf[2] = (fat_time >> 32) & 0xFF;
-	buf[3] = (fat_time >> 40) & 0xFF;
+	secs = rtc_tm_to_time64(&alarm->time);
+	hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2;
+	buf[0] = (hw_counter >> 16) & 0xFF;
+	buf[1] = (hw_counter >> 24) & 0xFF;
+	buf[2] = (hw_counter >> 32) & 0xFF;
+	buf[3] = (hw_counter >> 40) & 0xFF;
 
 	/* Set the alarm */
 	for (i = 0; i < 4; i++) {
@@ -193,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled)
 
 static const struct rtc_class_ops ab3100_rtc_ops = {
 	.read_time	= ab3100_rtc_read_time,
-	.set_mmss	= ab3100_rtc_set_mmss,
+	.set_mmss64	= ab3100_rtc_set_mmss,
 	.read_alarm	= ab3100_rtc_read_alarm,
 	.set_alarm	= ab3100_rtc_set_alarm,
 	.alarm_irq_enable = ab3100_rtc_irq_enable,
Signature · 1 line
1.9.1
#16 lore raw

Re: [RFC PATCH v2 4/9] rtc/ab3100: Update driver to address y2038/y2106 issues

Quoted 3 lines · On Tue, 13 Jan 2015 23:44:52 +0800 Xunlei Pang <[email protected]> wrote:

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This should probably be evaluated by
Linus Walleij <[email protected]>

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
Acked-by on v2 4/9
#17 lore raw

Re: [RFC PATCH v2 4/9] rtc/ab3100: Update driver to address y2038/y2106 issues

In reply to Xunlei Pang
Quoted 9 lines · Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_tm_to_time() with rtc_tm_to_time64()
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change ab3100_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

Quoted 4 lines

After this patch, the driver should not have any remaining y2038/y2106 issues.

Yours,
Linus Walleij

#18 lore raw

RFC PATCH v2 5/9 rtc/mc13xxx: Update driver to address y2038/y2106 issues

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change mc13xxx_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-mc13xxx.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/rtc/rtc-mc13xxx.c +14 -18
index 5bce904b..32df1d8 100644
@@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
 			return ret;
 	} while (days1 != days2);
 
-	rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm);
+	rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm);
 
 	return rtc_valid_tm(tm);
 }
 
-static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
 {
 	struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
 	unsigned int seconds, days;
 	unsigned int alarmseconds;
 	int ret;
 
-	seconds = secs % SEC_PER_DAY;
-	days = secs / SEC_PER_DAY;
+	days = div_s64_rem(secs, SEC_PER_DAY, &seconds);
 
 	mc13xxx_lock(priv->mc13xxx);
 
@@ -159,7 +158,7 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
 	struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
 	unsigned seconds, days;
-	unsigned long s1970;
+	time64_t s1970;
 	int enabled, pending;
 	int ret;
 
@@ -189,10 +188,10 @@ out:
 	alarm->enabled = enabled;
 	alarm->pending = pending;
 
-	s1970 = days * SEC_PER_DAY + seconds;
+	s1970 = (time64_t)days * SEC_PER_DAY + seconds;
 
-	rtc_time_to_tm(s1970, &alarm->time);
-	dev_dbg(dev, "%s: %lu\n", __func__, s1970);
+	rtc_time64_to_tm(s1970, &alarm->time);
+	dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970);
 
 	return 0;
 }
@@ -200,8 +199,8 @@ out:
 static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
 	struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
-	unsigned long s1970;
-	unsigned seconds, days;
+	time64_t s1970;
+	u32 seconds, days;
 	int ret;
 
 	mc13xxx_lock(priv->mc13xxx);
@@ -215,20 +214,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 	if (unlikely(ret))
 		goto out;
 
-	ret = rtc_tm_to_time(&alarm->time, &s1970);
-	if (unlikely(ret))
-		goto out;
+	s1970 = rtc_tm_to_time64(&alarm->time);
 
-	dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff",
-			s1970);
+	dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff",
+			(long long)s1970);
 
 	ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled,
 			MC13XXX_IRQ_TODA);
 	if (unlikely(ret))
 		goto out;
 
-	seconds = s1970 % SEC_PER_DAY;
-	days = s1970 / SEC_PER_DAY;
+	days = div_s64_rem(s1970, SEC_PER_DAY, &seconds);
 
 	ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days);
 	if (unlikely(ret))
@@ -268,7 +264,7 @@ static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev)
 
 static const struct rtc_class_ops mc13xxx_rtc_ops = {
 	.read_time = mc13xxx_rtc_read_time,
-	.set_mmss = mc13xxx_rtc_set_mmss,
+	.set_mmss64 = mc13xxx_rtc_set_mmss,
 	.read_alarm = mc13xxx_rtc_read_alarm,
 	.set_alarm = mc13xxx_rtc_set_alarm,
 	.alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
Signature · 1 line
1.9.1
#19 lore raw

Re: [RFC PATCH v2 5/9] rtc/mc13xxx: Update driver to address y2038/y2106 issues

Cc Uwe Kleine-Koenig <[email protected]>

Quoted 116 lines · Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change mc13xxx_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-mc13xxx.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/rtc/rtc-mc13xxx.c +14 -19
index 5bce904b..32df1d8 100644
@@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
                        return ret;
        } while (days1 != days2);
 
-       rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm);
+       rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm);
 
        return rtc_valid_tm(tm);
 }
 
-static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
 {
        struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
        unsigned int seconds, days;
        unsigned int alarmseconds;
        int ret;
 
-       seconds = secs % SEC_PER_DAY;
-       days = secs / SEC_PER_DAY;
+       days = div_s64_rem(secs, SEC_PER_DAY, &seconds);
 
        mc13xxx_lock(priv->mc13xxx);
 
@@ -159,7 +158,7 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
        struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
        unsigned seconds, days;
-       unsigned long s1970;
+       time64_t s1970;
        int enabled, pending;
        int ret;
 
@@ -189,10 +188,10 @@ out:
        alarm->enabled = enabled;
        alarm->pending = pending;
 
-       s1970 = days * SEC_PER_DAY + seconds;
+       s1970 = (time64_t)days * SEC_PER_DAY + seconds;
 
-       rtc_time_to_tm(s1970, &alarm->time);
-       dev_dbg(dev, "%s: %lu\n", __func__, s1970);
+       rtc_time64_to_tm(s1970, &alarm->time);
+       dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970);
 
        return 0;
 }
@@ -200,8 +199,8 @@ out:
 static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 {
        struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
-       unsigned long s1970;
-       unsigned seconds, days;
+       time64_t s1970;
+       u32 seconds, days;
        int ret;
 
        mc13xxx_lock(priv->mc13xxx);
@@ -215,20 +214,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
        if (unlikely(ret))
                goto out;
 
-       ret = rtc_tm_to_time(&alarm->time, &s1970);
-       if (unlikely(ret))
-               goto out;
+       s1970 = rtc_tm_to_time64(&alarm->time);
 
-       dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff",
-                       s1970);
+       dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff",
+                       (long long)s1970);
 
        ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled,
                        MC13XXX_IRQ_TODA);
        if (unlikely(ret))
                goto out;
 
-       seconds = s1970 % SEC_PER_DAY;
-       days = s1970 / SEC_PER_DAY;
+       days = div_s64_rem(s1970, SEC_PER_DAY, &seconds);
 
        ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days);
        if (unlikely(ret))
@@ -268,7 +264,7 @@ static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev)
 
 static const struct rtc_class_ops mc13xxx_rtc_ops = {
        .read_time = mc13xxx_rtc_read_time,
-       .set_mmss = mc13xxx_rtc_set_mmss,
+       .set_mmss64 = mc13xxx_rtc_set_mmss,
        .read_alarm = mc13xxx_rtc_read_alarm,
        .set_alarm = mc13xxx_rtc_set_alarm,
        .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
--

1.9.1

#20 lore raw

Re: [RFC PATCH v2 5/9] rtc/mc13xxx: Update driver to address y2038/y2106 issues

Hello,

Quoted 1 line · Xunlei Pang

Cc Uwe Kleine-Koenig <[email protected]>

Thanks, that was useful.

Quoted 26 lines · Xunlei Pang
Quoted 24 lines

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Change mc13xxx_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-mc13xxx.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/rtc/rtc-mc13xxx.c +0 -0
index 5bce904b..32df1d8 100644
@@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
                        return ret;
        } while (days1 != days2);
 
Quoted 8 lines

drivers/rtc/rtc-mc13xxx.c static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) · line 91

Quoted 8 lines
drivers/rtc/rtc-mc13xxx.c +2 -2
-       rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm);
+       rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm);
 
        return rtc_valid_tm(tm);
 }
 
-static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs)
+static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)

I don't know if there is a usual conversion rule, but I'd expect that the function is also renamed to get a suffix 64.

Other than that the patch looks good.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#21 lore raw

RFC PATCH v2 6/9 rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

rtc_class_ops's set_alarm() shouldn't deal with the alarm date, as this is handled in the rtc core.

See rtc_dev_ioctl()'s RTC_ALM_SET and RTC_WKALM_SET cases.

---
 drivers/rtc/rtc-mxc.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)
drivers/rtc/rtc-mxc.c +4 -18
index 3c3f8d1..a7b218f 100644
@@ -173,29 +173,18 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time)
  * This function updates the RTC alarm registers and then clears all the
  * interrupt status bits.
  */
-static int rtc_update_alarm(struct device *dev, struct rtc_time *alrm)
+static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm)
 {
-	struct rtc_time alarm_tm, now_tm;
-	unsigned long now, time;
+	unsigned long time;
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
 
-	now = get_alarm_or_time(dev, MXC_RTC_TIME);
-	rtc_time_to_tm(now, &now_tm);
-	alarm_tm.tm_year = now_tm.tm_year;
-	alarm_tm.tm_mon = now_tm.tm_mon;
-	alarm_tm.tm_mday = now_tm.tm_mday;
-	alarm_tm.tm_hour = alrm->tm_hour;
-	alarm_tm.tm_min = alrm->tm_min;
-	alarm_tm.tm_sec = alrm->tm_sec;
-	rtc_tm_to_time(&alarm_tm, &time);
+	rtc_tm_to_time(alrm, &time);
 
 	/* clear all the interrupt status bits */
 	writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR);
 	set_alarm_or_time(dev, MXC_RTC_ALARM, time);
-
-	return 0;
 }
 
 static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit,
@@ -346,11 +335,8 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-	int ret;
 
-	ret = rtc_update_alarm(dev, &alrm->time);
-	if (ret)
-		return ret;
+	rtc_update_alarm(dev, &alrm->time);
 
 	memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time));
 	mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled);
Signature · 1 line
1.9.1
#22 lore raw

Re: [RFC PATCH v2 6/9] rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time

Quoted 2 lines · On Tue, 13 Jan 2015 23:44:54 +0800 Xunlei Pang <[email protected]> wrote:

rtc_class_ops's set_alarm() shouldn't deal with the alarm date, as this is handled in the rtc core.

Please CC the author and ask him. The same applies for the other drivers.

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#23 lore raw

Re: [RFC PATCH v2 6/9] rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time

In reply to Xunlei Pang

Cc Fabio Estevam <[email protected]>

Quoted 66 lines · Xunlei Pang

From: Xunlei Pang <[email protected]>

rtc_class_ops's set_alarm() shouldn't deal with the alarm date, as this is handled in the rtc core.

See rtc_dev_ioctl()'s RTC_ALM_SET and RTC_WKALM_SET cases.

---
 drivers/rtc/rtc-mxc.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)
drivers/rtc/rtc-mxc.c +4 -19
index 3c3f8d1..a7b218f 100644
@@ -173,29 +173,18 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time)
  * This function updates the RTC alarm registers and then clears all the
  * interrupt status bits.
  */
-static int rtc_update_alarm(struct device *dev, struct rtc_time *alrm)
+static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm)
 {
-       struct rtc_time alarm_tm, now_tm;
-       unsigned long now, time;
+       unsigned long time;
        struct platform_device *pdev = to_platform_device(dev);
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
        void __iomem *ioaddr = pdata->ioaddr;
 
-       now = get_alarm_or_time(dev, MXC_RTC_TIME);
-       rtc_time_to_tm(now, &now_tm);
-       alarm_tm.tm_year = now_tm.tm_year;
-       alarm_tm.tm_mon = now_tm.tm_mon;
-       alarm_tm.tm_mday = now_tm.tm_mday;
-       alarm_tm.tm_hour = alrm->tm_hour;
-       alarm_tm.tm_min = alrm->tm_min;
-       alarm_tm.tm_sec = alrm->tm_sec;
-       rtc_tm_to_time(&alarm_tm, &time);
+       rtc_tm_to_time(alrm, &time);
 
        /* clear all the interrupt status bits */
        writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR);
        set_alarm_or_time(dev, MXC_RTC_ALARM, time);
-
-       return 0;
 }
 
 static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit,
@@ -346,11 +335,8 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-       int ret;
 
-       ret = rtc_update_alarm(dev, &alrm->time);
-       if (ret)
-               return ret;
+       rtc_update_alarm(dev, &alrm->time);
 
        memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time));
        mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled);
--

1.9.1

#24 lore raw

RFC PATCH v2 7/9 rtc/mxc: Convert get_alarm_or_time()/set_alarm_or_time() to use time64_t

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

We want to convert mxc_rtc_set_mmss() to use rtc_class_ops's set_mmss64(), but it uses get_alarm_or_time()/set_alarm_or_time() internal interfaces which are y2038 unsafe.

So here as a separate patch, it converts these two internal interfaces of "mxc" to use safe time64_t to make some preparations.

---
 drivers/rtc/rtc-mxc.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/rtc/rtc-mxc.c +14 -15
index a7b218f..83cba23 100644
@@ -106,7 +106,7 @@ static inline int is_imx1_rtc(struct rtc_plat_data *data)
  * This function is used to obtain the RTC time or the alarm value in
  * second.
  */
-static u32 get_alarm_or_time(struct device *dev, int time_alarm)
+static time64_t get_alarm_or_time(struct device *dev, int time_alarm)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
@@ -129,29 +129,28 @@ static u32 get_alarm_or_time(struct device *dev, int time_alarm)
 	hr = hr_min >> 8;
 	min = hr_min & 0xff;
 
-	return (((day * 24 + hr) * 60) + min) * 60 + sec;
+	return ((((time64_t)day * 24 + hr) * 60) + min) * 60 + sec;
 }
 
 /*
  * This function sets the RTC alarm value or the time value.
  */
-static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time)
+static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time)
 {
-	u32 day, hr, min, sec, temp;
+	u32 tod, day, hr, min, sec, temp;
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
 
-	day = time / 86400;
-	time -= day * 86400;
+	day = div_s64_rem(time, 86400, &tod);
 
 	/* time is within a day now */
-	hr = time / 3600;
-	time -= hr * 3600;
+	hr = tod / 3600;
+	tod -= hr * 3600;
 
 	/* time is within an hour now */
-	min = time / 60;
-	sec = time - min * 60;
+	min = tod / 60;
+	sec = tod - min * 60;
 
 	temp = (hr << 8) + min;
 
@@ -175,12 +174,12 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time)
  */
 static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm)
 {
-	unsigned long time;
+	time64_t time;
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
 
-	rtc_tm_to_time(alrm, &time);
+	time = rtc_tm_to_time64(alrm);
 
 	/* clear all the interrupt status bits */
 	writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR);
@@ -272,14 +271,14 @@ static int mxc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
  */
 static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	u32 val;
+	time64_t val;
 
 	/* Avoid roll-over from reading the different registers */
 	do {
 		val = get_alarm_or_time(dev, MXC_RTC_TIME);
 	} while (val != get_alarm_or_time(dev, MXC_RTC_TIME));
 
-	rtc_time_to_tm(val, tm);
+	rtc_time64_to_tm(val, tm);
 
 	return 0;
 }
@@ -322,7 +321,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 	void __iomem *ioaddr = pdata->ioaddr;
 
-	rtc_time_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time);
+	rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time);
 	alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0;
 
 	return 0;
Signature · 1 line
1.9.1
#25 lore raw

RFC PATCH v2 8/9 rtc/mxc: Update driver to address y2038/y2106 issues

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

This driver has a number of y2038/y2106 issues.

This patch resolves them by:
- Replace rtc_time_to_tm() with rtc_time64_to_tm()
- Replace rtc_tm_to_time() with rtc_tm_to_time64()
- Change mxc_rtc_set_mmss() to use rtc_class_ops's set_mmss64()

After this patch, the driver should not have any remaining y2038/y2106 issues.

---
 drivers/rtc/rtc-mxc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/rtc-mxc.c +4 -4
index 83cba23..09d422b 100644
@@ -286,7 +286,7 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm)
 /*
  * This function sets the internal RTC time based on tm in Gregorian date.
  */
-static int mxc_rtc_set_mmss(struct device *dev, unsigned long time)
+static int mxc_rtc_set_mmss(struct device *dev, time64_t time)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
@@ -297,9 +297,9 @@ static int mxc_rtc_set_mmss(struct device *dev, unsigned long time)
 	if (is_imx1_rtc(pdata)) {
 		struct rtc_time tm;
 
-		rtc_time_to_tm(time, &tm);
+		rtc_time64_to_tm(time, &tm);
 		tm.tm_year = 70;
-		rtc_tm_to_time(&tm, &time);
+		time = rtc_tm_to_time64(&tm);
 	}
 
 	/* Avoid roll-over from reading the different registers */
@@ -347,7 +347,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 static struct rtc_class_ops mxc_rtc_ops = {
 	.release		= mxc_rtc_release,
 	.read_time		= mxc_rtc_read_time,
-	.set_mmss		= mxc_rtc_set_mmss,
+	.set_mmss64		= mxc_rtc_set_mmss,
 	.read_alarm		= mxc_rtc_read_alarm,
 	.set_alarm		= mxc_rtc_set_alarm,
 	.alarm_irq_enable	= mxc_rtc_alarm_irq_enable,
Signature · 1 line
1.9.1
#26 lore raw

RFC PATCH v2 9/9 alpha: change to use rtc_class_ops's set_mmss64()

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

Change alpha_rtc_set_mmss() and remote_set_mmss() to use rtc_class_ops's set_mmss64().

---
 arch/alpha/kernel/rtc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/alpha/kernel/rtc.c +4 -4
index c8d284d..f535a3f 100644
@@ -116,7 +116,7 @@ alpha_rtc_set_time(struct device *dev, struct rtc_time *tm)
 }
 
 static int
-alpha_rtc_set_mmss(struct device *dev, unsigned long nowtime)
+alpha_rtc_set_mmss(struct device *dev, time64_t nowtime)
 {
 	int retval = 0;
 	int real_seconds, real_minutes, cmos_minutes;
@@ -211,7 +211,7 @@ alpha_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
 static const struct rtc_class_ops alpha_rtc_ops = {
 	.read_time = alpha_rtc_read_time,
 	.set_time = alpha_rtc_set_time,
-	.set_mmss = alpha_rtc_set_mmss,
+	.set_mmss64 = alpha_rtc_set_mmss,
 	.ioctl = alpha_rtc_ioctl,
 };
 
@@ -276,7 +276,7 @@ do_remote_mmss(void *data)
 }
 
 static int
-remote_set_mmss(struct device *dev, unsigned long now)
+remote_set_mmss(struct device *dev, time64_t now)
 {
 	union remote_data x;
 	if (smp_processor_id() != boot_cpuid) {
@@ -290,7 +290,7 @@ remote_set_mmss(struct device *dev, unsigned long now)
 static const struct rtc_class_ops remote_rtc_ops = {
 	.read_time = remote_read_time,
 	.set_time = remote_set_time,
-	.set_mmss = remote_set_mmss,
+	.set_mmss64 = remote_set_mmss,
 	.ioctl = alpha_rtc_ioctl,
 };
 #endif
Signature · 1 line
1.9.1