Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Feng Tang and committed by
Linus Torvalds
57e6319d f2ee4421

+13 -10
+2 -2
arch/x86/platform/mrst/vrtc.c
··· 76 76 77 77 spin_unlock_irqrestore(&rtc_lock, flags); 78 78 79 - /* vRTC YEAR reg contains the offset to 1960 */ 80 - year += 1960; 79 + /* vRTC YEAR reg contains the offset to 1972 */ 80 + year += 1972; 81 81 82 82 printk(KERN_INFO "vRTC: sec: %d min: %d hour: %d day: %d " 83 83 "mon: %d year: %d\n", sec, min, hour, mday, mon, year);
+11 -8
drivers/rtc/rtc-mrst.c
··· 76 76 /* 77 77 * rtc_time's year contains the increment over 1900, but vRTC's YEAR 78 78 * 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, 80 80 * and does the translation at read/write time. 81 81 * 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 83 83 * 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. 85 88 */ 86 89 static int mrst_read_time(struct device *dev, struct rtc_time *time) 87 90 { ··· 102 99 time->tm_year = vrtc_cmos_read(RTC_YEAR); 103 100 spin_unlock_irqrestore(&rtc_lock, flags); 104 101 105 - /* Adjust for the 1960/1900 */ 106 - time->tm_year += 60; 102 + /* Adjust for the 1972/1900 */ 103 + time->tm_year += 72; 107 104 time->tm_mon--; 108 - return RTC_24H; 105 + return rtc_valid_tm(time); 109 106 } 110 107 111 108 static int mrst_set_time(struct device *dev, struct rtc_time *time) ··· 122 119 min = time->tm_min; 123 120 sec = time->tm_sec; 124 121 125 - if (yrs < 70 || yrs > 138) 122 + if (yrs < 72 || yrs > 138) 126 123 return -EINVAL; 127 - yrs -= 60; 124 + yrs -= 72; 128 125 129 126 spin_lock_irqsave(&rtc_lock, flags); 130 127