Commit bc10aa93 authored by Xunlei Pang's avatar Xunlei Pang Committed by John Stultz

rtc: Update interface.c to use y2038-safe time interfaces

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().

Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: default avatarXunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
parent 2e0c78ee
...@@ -73,10 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -73,10 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
else if (rtc->ops->set_time) else if (rtc->ops->set_time)
err = rtc->ops->set_time(rtc->dev.parent, tm); err = rtc->ops->set_time(rtc->dev.parent, tm);
else if (rtc->ops->set_mmss) { else if (rtc->ops->set_mmss) {
unsigned long secs; time64_t secs64 = rtc_tm_to_time64(tm);
err = rtc_tm_to_time(tm, &secs); err = rtc->ops->set_mmss(rtc->dev.parent, secs64);
if (err == 0)
err = rtc->ops->set_mmss(rtc->dev.parent, secs);
} else } else
err = -EINVAL; err = -EINVAL;
...@@ -105,7 +103,7 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) ...@@ -105,7 +103,7 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
err = rtc->ops->read_time(rtc->dev.parent, &old); err = rtc->ops->read_time(rtc->dev.parent, &old);
if (err == 0) { 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 * avoid writing when we're going to change the day of
...@@ -157,7 +155,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -157,7 +155,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
int err; int err;
struct rtc_time before, now; struct rtc_time before, now;
int first_time = 1; int first_time = 1;
unsigned long t_now, t_alm; time64_t t_now, t_alm;
enum { none, day, month, year } missing = none; enum { none, day, month, year } missing = none;
unsigned days; unsigned days;
...@@ -258,8 +256,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -258,8 +256,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
} }
/* with luck, no rollover is needed */ /* with luck, no rollover is needed */
rtc_tm_to_time(&now, &t_now); t_now = rtc_tm_to_time64(&now);
rtc_tm_to_time(&alarm->time, &t_alm); t_alm = rtc_tm_to_time64(&alarm->time);
if (t_now < t_alm) if (t_now < t_alm)
goto done; goto done;
...@@ -273,7 +271,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -273,7 +271,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
case day: case day:
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day"); dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day");
t_alm += 24 * 60 * 60; t_alm += 24 * 60 * 60;
rtc_time_to_tm(t_alm, &alarm->time); rtc_time64_to_tm(t_alm, &alarm->time);
break; break;
/* Month rollover ... if it's the 31th, an alarm on the 3rd will /* Month rollover ... if it's the 31th, an alarm on the 3rd will
...@@ -346,19 +344,19 @@ EXPORT_SYMBOL_GPL(rtc_read_alarm); ...@@ -346,19 +344,19 @@ EXPORT_SYMBOL_GPL(rtc_read_alarm);
static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{ {
struct rtc_time tm; struct rtc_time tm;
long now, scheduled; time64_t now, scheduled;
int err; int err;
err = rtc_valid_tm(&alarm->time); err = rtc_valid_tm(&alarm->time);
if (err) if (err)
return 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 */ /* Make sure we're not setting alarms in the past */
err = __rtc_read_time(rtc, &tm); err = __rtc_read_time(rtc, &tm);
if (err) if (err)
return err; return err;
rtc_tm_to_time(&tm, &now); now = rtc_tm_to_time64(&tm);
if (scheduled <= now) if (scheduled <= now)
return -ETIME; return -ETIME;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment