2015-04-15 09:21:32

by Xunlei Pang

[permalink] [raw]
Subject: [PATCH 1/5] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()

From: Xunlei Pang <[email protected]>

pcf8563_rtc_set_alarm() uses deprecated rtc_tm_to_time()
and rtc_time_to_tm(), which will overflow in year 2106
on 32-bit machines.

This patch solves this by:
- Replacing rtc_time_to_tm() with rtc_time64_to_tm()
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()

Signed-off-by: Xunlei Pang <[email protected]>
---
drivers/rtc/rtc-pcf8563.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 96fb32e..4ce66ad 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -368,13 +368,13 @@ static int pcf8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
struct i2c_client *client = to_i2c_client(dev);
unsigned char buf[4];
int err;
- unsigned long alarm_time;

/* The alarm has no seconds, round up to nearest minute */
if (tm->time.tm_sec) {
- rtc_tm_to_time(&tm->time, &alarm_time);
- alarm_time += 60-tm->time.tm_sec;
- rtc_time_to_tm(alarm_time, &tm->time);
+ time64_t alarm_time = rtc_tm_to_time64(&tm->time);
+
+ alarm_time += 60 - tm->time.tm_sec;
+ rtc_time64_to_tm(alarm_time, &tm->time);
}

dev_dbg(dev, "%s, min=%d hour=%d wday=%d mday=%d "
--
1.9.1


2015-04-15 09:21:50

by Xunlei Pang

[permalink] [raw]
Subject: [PATCH 2/5] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time()

From: Xunlei Pang <[email protected]>

isl1208_i2c_set_alarm() uses deprecated rtc_tm_to_time(),
which will overflow in year 2106 on 32-bit machines.

This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()

Cc: Herbert Valerio Riedel <[email protected]>
Signed-off-by: Xunlei Pang <[email protected]>
---
drivers/rtc/rtc-isl1208.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index c3c549d..06113e8 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -370,19 +370,16 @@ isl1208_i2c_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
struct rtc_time *alarm_tm = &alarm->time;
u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
const int offs = ISL1208_REG_SCA;
- unsigned long rtc_secs, alarm_secs;
+ time64_t rtc_secs, alarm_secs;
struct rtc_time rtc_tm;
int err, enable;

err = isl1208_i2c_read_time(client, &rtc_tm);
if (err)
return err;
- err = rtc_tm_to_time(&rtc_tm, &rtc_secs);
- if (err)
- return err;
- err = rtc_tm_to_time(alarm_tm, &alarm_secs);
- if (err)
- return err;
+
+ rtc_secs = rtc_tm_to_time64(&rtc_tm);
+ alarm_secs = rtc_tm_to_time64(alarm_tm);

/* If the alarm time is before the current time disable the alarm */
if (!alarm->enabled || alarm_secs <= rtc_secs)
--
1.9.1

2015-04-15 09:21:38

by Xunlei Pang

[permalink] [raw]
Subject: [PATCH 3/5] drivers/rtc/sunxi: Replace deprecated rtc_tm_to_time()

From: Xunlei Pang <[email protected]>

sunxi_rtc_setalarm() uses deprecated rtc_tm_to_time(),
which will overflow in year 2106 on 32-bit machines.

This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()

Also remove the unnecessary initial zeroing of some
local variables in sunxi_rtc_setalarm().

Cc: Carlo Caione <[email protected]>
Signed-off-by: Xunlei Pang <[email protected]>
---
drivers/rtc/rtc-sunxi.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c
index 6e678fa..7f22753 100644
--- a/drivers/rtc/rtc-sunxi.c
+++ b/drivers/rtc/rtc-sunxi.c
@@ -269,14 +269,13 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
struct sunxi_rtc_dev *chip = dev_get_drvdata(dev);
struct rtc_time *alrm_tm = &wkalrm->time;
struct rtc_time tm_now;
- u32 alrm = 0;
- unsigned long time_now = 0;
- unsigned long time_set = 0;
- unsigned long time_gap = 0;
- unsigned long time_gap_day = 0;
- unsigned long time_gap_hour = 0;
- unsigned long time_gap_min = 0;
- int ret = 0;
+ u32 alrm;
+ time64_t time_set, time_now;
+ unsigned long time_gap;
+ unsigned long time_gap_day;
+ unsigned long time_gap_hour;
+ unsigned long time_gap_min;
+ int ret;

ret = sunxi_rtc_gettime(dev, &tm_now);
if (ret < 0) {
@@ -284,13 +283,18 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
return -EINVAL;
}

- rtc_tm_to_time(alrm_tm, &time_set);
- rtc_tm_to_time(&tm_now, &time_now);
+ time_set = rtc_tm_to_time64(alrm_tm);
+ time_now = rtc_tm_to_time64(&tm_now);
if (time_set <= time_now) {
dev_err(dev, "Date to set in the past\n");
return -EINVAL;
}

+ if (time_set > time_now + 255 * SEC_IN_DAY) {
+ dev_err(dev, "Day must be in the range 0 - 255\n");
+ return -EINVAL;
+ }
+
time_gap = time_set - time_now;
time_gap_day = time_gap / SEC_IN_DAY;
time_gap -= time_gap_day * SEC_IN_DAY;
@@ -299,11 +303,6 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
time_gap_min = time_gap / SEC_IN_MIN;
time_gap -= time_gap_min * SEC_IN_MIN;

- if (time_gap_day > 255) {
- dev_err(dev, "Day must be in the range 0 - 255\n");
- return -EINVAL;
- }
-
sunxi_rtc_setaie(0, chip);
writel(0, chip->base + SUNXI_ALRM_DHMS);
usleep_range(100, 300);
--
1.9.1

2015-04-15 09:22:09

by Xunlei Pang

[permalink] [raw]
Subject: [PATCH 4/5] drivers/rtc/pl030: Replace deprecated rtc_tm_to_time() and rtc_time_to_tm()

From: Xunlei Pang <[email protected]>

The driver uses deprecated rtc_tm_to_time() and rtc_time_to_tm(),
which will overflow in year 2106 on 32-bit machines.

This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()
- Replacing rtc_time_to_tm() with rtc_time64_to_tm()

Cc: Russell King <[email protected]>
Signed-off-by: Xunlei Pang <[email protected]>
---
drivers/rtc/rtc-pl030.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
index f85a1a9..d874b6e 100644
--- a/drivers/rtc/rtc-pl030.c
+++ b/drivers/rtc/rtc-pl030.c
@@ -39,32 +39,34 @@ static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);

- rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
+ rtc_time64_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
return 0;
}

static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
- unsigned long time;
+ time64_t time;
int ret;

/*
* At the moment, we can only deal with non-wildcarded alarm times.
*/
ret = rtc_valid_tm(&alrm->time);
- if (ret == 0)
- ret = rtc_tm_to_time(&alrm->time, &time);
- if (ret == 0)
- writel(time, rtc->base + RTC_MR);
- return ret;
+ if (ret)
+ return ret;
+
+ time = rtc_tm_to_time64(&alrm->time);
+ writel(time, rtc->base + RTC_MR);
+
+ return 0;
}

static int pl030_read_time(struct device *dev, struct rtc_time *tm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);

- rtc_time_to_tm(readl(rtc->base + RTC_DR), tm);
+ rtc_time64_to_tm(readl(rtc->base + RTC_DR), tm);

return 0;
}
@@ -80,14 +82,12 @@ static int pl030_read_time(struct device *dev, struct rtc_time *tm)
static int pl030_set_time(struct device *dev, struct rtc_time *tm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
- unsigned long time;
- int ret;
+ time64_t time;

- ret = rtc_tm_to_time(tm, &time);
- if (ret == 0)
- writel(time + 1, rtc->base + RTC_LR);
+ time = rtc_tm_to_time64(tm);
+ writel(time + 1, rtc->base + RTC_LR);

- return ret;
+ return 0;
}

static const struct rtc_class_ops pl030_ops = {
--
1.9.1

2015-04-15 09:22:04

by Xunlei Pang

[permalink] [raw]
Subject: [PATCH 5/5] drivers/rtc/sa1100: Replace deprecated rtc_tm_to_time() and rtc_time_to_tm()

From: Xunlei Pang <[email protected]>

The driver uses deprecated rtc_tm_to_time() and rtc_time_to_tm(),
which will overflow in year 2106 on 32-bit machines.

This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()
- Replacing rtc_time_to_tm() with rtc_time64_to_tm()

Cc: CIH <[email protected]>
Cc: Nicolas Pitre <[email protected]>
Cc: Andrew Christian <[email protected]>
Cc: Richard Purdie <[email protected]>
Signed-off-by: Xunlei Pang <[email protected]>
---
drivers/rtc/rtc-sa1100.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index b6e1ca0..625a320 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -157,19 +157,14 @@ static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)

static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
- rtc_time_to_tm(RCNR, tm);
+ rtc_time64_to_tm(RCNR, tm);
return 0;
}

static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
- unsigned long time;
- int ret;
-
- ret = rtc_tm_to_time(tm, &time);
- if (ret == 0)
- RCNR = time;
- return ret;
+ RCNR = rtc_tm_to_time64(tm);
+ return 0;
}

static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -185,23 +180,17 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct sa1100_rtc *info = dev_get_drvdata(dev);
- unsigned long time;
- int ret;

spin_lock_irq(&info->lock);
- ret = rtc_tm_to_time(&alrm->time, &time);
- if (ret != 0)
- goto out;
RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
- RTAR = time;
+ RTAR = rtc_tm_to_time64(&alrm->time);
if (alrm->enabled)
RTSR |= RTSR_ALE;
else
RTSR &= ~RTSR_ALE;
-out:
spin_unlock_irq(&info->lock);

- return ret;
+ return 0;
}

static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
--
1.9.1

2015-04-15 09:35:29

by Russell King - ARM Linux

[permalink] [raw]
Subject: Re: [PATCH 4/5] drivers/rtc/pl030: Replace deprecated rtc_tm_to_time() and rtc_time_to_tm()

On Wed, Apr 15, 2015 at 05:20:10PM +0800, Xunlei Pang wrote:
> From: Xunlei Pang <[email protected]>
>
> The driver uses deprecated rtc_tm_to_time() and rtc_time_to_tm(),
> which will overflow in year 2106 on 32-bit machines.
>
> This patch solves this by:
> - Replacing rtc_tm_to_time() with rtc_tm_to_time64()
> - Replacing rtc_time_to_tm() with rtc_time64_to_tm()
>
> Cc: Russell King <[email protected]>
> Signed-off-by: Xunlei Pang <[email protected]>

NAK.

How does this fix anything? The RTC contains 32-bit registers. Even
if you convert the struct tm to a 64-bit time, you can only write the
lowest 32-bits to the hardware. You can onyl read the lowest 32-bits
from the hardware too.

This patch solves /nothing/. In fact, it hides the fact that this RTC
is unable to represent dates after 2106.

--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

2015-04-29 23:28:29

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [5/5] drivers/rtc/sa1100: Replace deprecated rtc_tm_to_time() and rtc_time_to_tm()

Hi,

On 15/04/2015 at 17:20:11 +0800, Xunlei Pang wrote :
> From: Xunlei Pang <[email protected]>
>
> The driver uses deprecated rtc_tm_to_time() and rtc_time_to_tm(),
> which will overflow in year 2106 on 32-bit machines.
>
> This patch solves this by:
> - Replacing rtc_tm_to_time() with rtc_tm_to_time64()
> - Replacing rtc_time_to_tm() with rtc_time64_to_tm()
>
> Cc: CIH <[email protected]>
> Cc: Nicolas Pitre <[email protected]>
> Cc: Andrew Christian <[email protected]>
> Cc: Richard Purdie <[email protected]>
> Signed-off-by: Xunlei Pang <[email protected]>
> ---
> drivers/rtc/rtc-sa1100.c | 21 +++++----------------
> 1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
> index b6e1ca0..625a320 100644
> --- a/drivers/rtc/rtc-sa1100.c
> +++ b/drivers/rtc/rtc-sa1100.c
> @@ -157,19 +157,14 @@ static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
>
> static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
> {
> - rtc_time_to_tm(RCNR, tm);
> + rtc_time64_to_tm(RCNR, tm);
> return 0;
> }
>
> static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
> {
> - unsigned long time;
> - int ret;
> -
> - ret = rtc_tm_to_time(tm, &time);
> - if (ret == 0)
> - RCNR = time;
> - return ret;
> + RCNR = rtc_tm_to_time64(tm);

For the same reason that Russell pointed in patch 4/5, this hides that
it doesn't work after 2106-02-07 06:28:16 as the register is still 32
bits.
I would prefer that you return an error in that case.


--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com