Commit f4b82d39 authored by Benjamin Gaignard's avatar Benjamin Gaignard Committed by Alexandre Belloni

rtc: st-lpc: make it robust against y2038/2106 bug

Make driver use u64 variables and functions to be sure that
it will support dates after year 2038.
Signed-off-by: default avatarBenjamin Gaignard <benjamin.gaignard@linaro.org>
Acked-by: default avatarPatrice Chotard <patrice.chotard@st.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 69c31226
...@@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb; lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
do_div(lpt, rtc->clkrate); do_div(lpt, rtc->clkrate);
rtc_time_to_tm(lpt, tm); rtc_time64_to_tm(lpt, tm);
return 0; return 0;
} }
...@@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int st_rtc_set_time(struct device *dev, struct rtc_time *tm) static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct st_rtc *rtc = dev_get_drvdata(dev); struct st_rtc *rtc = dev_get_drvdata(dev);
unsigned long long lpt; unsigned long long lpt, secs;
unsigned long secs, flags; unsigned long flags;
int ret;
ret = rtc_tm_to_time(tm, &secs); secs = rtc_tm_to_time64(tm);
if (ret)
return ret;
lpt = (unsigned long long)secs * rtc->clkrate; lpt = (unsigned long long)secs * rtc->clkrate;
...@@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t) ...@@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
{ {
struct st_rtc *rtc = dev_get_drvdata(dev); struct st_rtc *rtc = dev_get_drvdata(dev);
struct rtc_time now; struct rtc_time now;
unsigned long now_secs; unsigned long long now_secs;
unsigned long alarm_secs; unsigned long long alarm_secs;
unsigned long long lpa; unsigned long long lpa;
st_rtc_read_time(dev, &now); st_rtc_read_time(dev, &now);
rtc_tm_to_time(&now, &now_secs); now_secs = rtc_tm_to_time64(&now);
rtc_tm_to_time(&t->time, &alarm_secs); alarm_secs = rtc_tm_to_time64(&t->time);
/* Invalid alarm time */ /* Invalid alarm time */
if (now_secs > alarm_secs) if (now_secs > alarm_secs)
......
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