drivers/rtc/mc13xxx: Update driver to address y2038/y2106 issues

This driver has a number of y2038/y2106 issues.

This patch resolves them by:

  - Replacing rtc_time_to_tm() with rtc_time64_to_tm()
  - Changing 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.

Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1427945681-29972-11-git-send-email-john.stultz@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Xunlei Pang 2015-04-01 20:34:30 -07:00 committed by Ingo Molnar
parent 5c7e11bc66
commit 0307b0d77a
1 changed files with 14 additions and 18 deletions

View File

@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
return ret; return ret;
} while (days1 != days2); } 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); 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); struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned int seconds, days; unsigned int seconds, days;
unsigned int alarmseconds; unsigned int alarmseconds;
int ret; int ret;
seconds = secs % SEC_PER_DAY; days = div_s64_rem(secs, SEC_PER_DAY, &seconds);
days = secs / SEC_PER_DAY;
mc13xxx_lock(priv->mc13xxx); 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); struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned seconds, days; unsigned seconds, days;
unsigned long s1970; time64_t s1970;
int enabled, pending; int enabled, pending;
int ret; int ret;
@ -189,10 +188,10 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
alarm->enabled = enabled; alarm->enabled = enabled;
alarm->pending = pending; alarm->pending = pending;
s1970 = days * SEC_PER_DAY + seconds; s1970 = (time64_t)days * SEC_PER_DAY + seconds;
rtc_time_to_tm(s1970, &alarm->time); rtc_time64_to_tm(s1970, &alarm->time);
dev_dbg(dev, "%s: %lu\n", __func__, s1970); dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970);
return 0; return 0;
} }
@ -200,8 +199,8 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct mc13xxx_rtc *priv = dev_get_drvdata(dev); struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned long s1970; time64_t s1970;
unsigned seconds, days; u32 seconds, days;
int ret; int ret;
mc13xxx_lock(priv->mc13xxx); mc13xxx_lock(priv->mc13xxx);
@ -215,20 +214,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (unlikely(ret)) if (unlikely(ret))
goto out; goto out;
ret = rtc_tm_to_time(&alarm->time, &s1970); s1970 = rtc_tm_to_time64(&alarm->time);
if (unlikely(ret))
goto out;
dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff",
s1970); (long long)s1970);
ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled,
MC13XXX_IRQ_TODA); MC13XXX_IRQ_TODA);
if (unlikely(ret)) if (unlikely(ret))
goto out; goto out;
seconds = s1970 % SEC_PER_DAY; days = div_s64_rem(s1970, SEC_PER_DAY, &seconds);
days = s1970 / SEC_PER_DAY;
ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days);
if (unlikely(ret)) 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 = { static const struct rtc_class_ops mc13xxx_rtc_ops = {
.read_time = mc13xxx_rtc_read_time, .read_time = mc13xxx_rtc_read_time,
.set_mmss = mc13xxx_rtc_set_mmss, .set_mmss64 = mc13xxx_rtc_set_mmss,
.read_alarm = mc13xxx_rtc_read_alarm, .read_alarm = mc13xxx_rtc_read_alarm,
.set_alarm = mc13xxx_rtc_set_alarm, .set_alarm = mc13xxx_rtc_set_alarm,
.alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,