Skip to content

Commit 57e6319

Browse files
ftang1torvalds
authored andcommitted
vrtc: change its year offset from 1960 to 1972
Real world year equals the value in vrtc YEAR register plus an offset. We used 1960 as the offset to make leap year consistent, but for a device's first use, its YEAR register is 0 and the system year will be parsed as 1960 which is not a valid UNIX time and will cause many applications to fail mysteriously. So we use 1972 instead to fix this issue. Updated patch which adds a sanity check suggested by Mathias This isn't a change in behaviour for systems, because 1972 is the one we actually use. It's the old version in upstream which is out of sync with all devices. Signed-off-by: Feng Tang <feng.tang@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f2ee442 commit 57e6319

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎arch/x86/platform/mrst/vrtc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ unsigned long vrtc_get_time(void)
7676

7777
spin_unlock_irqrestore(&rtc_lock, flags);
7878

79-
/* vRTC YEAR reg contains the offset to 1960 */
80-
year += 1960;
79+
/* vRTC YEAR reg contains the offset to 1972 */
80+
year += 1972;
8181

8282
printk(KERN_INFO "vRTC: sec: %d min: %d hour: %d day: %d "
8383
"mon: %d year: %d\n", sec, min, hour, mday, mon, year);

‎drivers/rtc/rtc-mrst.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ static inline unsigned char vrtc_is_updating(void)
7676
/*
7777
* rtc_time's year contains the increment over 1900, but vRTC's YEAR
7878
* register can't be programmed to value larger than 0x64, so vRTC
79-
* driver chose to use 1960 (1970 is UNIX time start point) as the base,
79+
* driver chose to use 1972 (1970 is UNIX time start point) as the base,
8080
* and does the translation at read/write time.
8181
*
82-
* Why not just use 1970 as the offset? it's because using 1960 will
82+
* Why not just use 1970 as the offset? it's because using 1972 will
8383
* make it consistent in leap year setting for both vrtc and low-level
84-
* physical rtc devices.
84+
* physical rtc devices. Then why not use 1960 as the offset? If we use
85+
* 1960, for a device's first use, its YEAR register is 0 and the system
86+
* year will be parsed as 1960 which is not a valid UNIX time and will
87+
* cause many applications to fail mysteriously.
8588
*/
8689
static int mrst_read_time(struct device *dev, struct rtc_time *time)
8790
{
@@ -99,10 +102,10 @@ static int mrst_read_time(struct device *dev, struct rtc_time *time)
99102
time->tm_year = vrtc_cmos_read(RTC_YEAR);
100103
spin_unlock_irqrestore(&rtc_lock, flags);
101104

102-
/* Adjust for the 1960/1900 */
103-
time->tm_year += 60;
105+
/* Adjust for the 1972/1900 */
106+
time->tm_year += 72;
104107
time->tm_mon--;
105-
return RTC_24H;
108+
return rtc_valid_tm(time);
106109
}
107110

108111
static int mrst_set_time(struct device *dev, struct rtc_time *time)
@@ -119,9 +122,9 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time)
119122
min = time->tm_min;
120123
sec = time->tm_sec;
121124

122-
if (yrs < 70 || yrs > 138)
125+
if (yrs < 72 || yrs > 138)
123126
return -EINVAL;
124-
yrs -= 60;
127+
yrs -= 72;
125128

126129
spin_lock_irqsave(&rtc_lock, flags);
127130

0 commit comments

Comments
 (0)