summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-12-01 23:14:10 +0100
committerTom Rini <trini@konsulko.com>2018-12-01 18:03:14 -0500
commit952061352acfd24034e6990b6b7d32cded020c0a (patch)
tree222547f2a356f4d7cba9ae401101a3635cf62583 /drivers/rtc
parentc1d6e0bbfdb50f9041a42bd4ce3af809a09ff7d1 (diff)
drivers: rtc: correctly convert seconds to time structure
Variable 'days' must be defined as signed int. Otherwise the conversion fails for some dates, e.g. 2004-08-25. Cf function rtc_time64_to_tm() in the Linux kernel source. Fixes: 992c1db45591 "drivers: rtc: resolve year 2038 problem in rtc_to_tm" Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-lib.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index b8a7a8b2d3..6528ddfebb 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -31,10 +31,14 @@ static int rtc_month_days(unsigned int month, unsigned int year)
/*
* rtc_to_tm - Converts u64 to rtc_time.
* Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
+ *
+ * This function is copied from rtc_time64_to_tm() in the Linux kernel.
+ * But in U-Boot January is month 1 and we do not subtract 1900 from the year.
*/
void rtc_to_tm(u64 time, struct rtc_time *tm)
{
- unsigned int month, year, secs, days;
+ unsigned int month, year, secs;
+ int days;
days = div_u64_rem(time, 86400, &secs);