Skip to content

Commit

Permalink
rtc: Update interface.c to use y2038-safe time interfaces
Browse files Browse the repository at this point in the history
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: Xunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
  • Loading branch information
Xunlei Pang authored and John Stultz committed Jan 24, 2015
1 parent 2e0c78e commit bc10aa9
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions drivers/rtc/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
else if (rtc->ops->set_time)
err = rtc->ops->set_time(rtc->dev.parent, tm);
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;

Expand Down Expand Up @@ -105,7 +103,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
Expand Down Expand Up @@ -157,7 +155,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;

Expand Down Expand Up @@ -258,8 +256,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;

Expand All @@ -273,7 +271,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
Expand Down Expand Up @@ -346,19 +344,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;
/*
Expand Down

0 comments on commit bc10aa9

Please sign in to comment.