Skip to content

Commit 68f78c7

Browse files
Csókás, Bencealexandrebelloni
authored andcommitted
rtc: ds1307: Clamp year to valid BCD (0-99) in set_time()
`tm_year` may go up to 299 if the device supports the century bit. Therefore, subtracting may not give us a valid 2-digit number, but modulo does. Co-developed-by: Szentendrei, Tamás <[email protected]> Signed-off-by: Szentendrei, Tamás <[email protected]> Signed-off-by: Csókás, Bence <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 35a34f0 commit 68f78c7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/rtc/rtc-ds1307.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
359359
regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);
360360

361361
/* assume 20YY not 19YY */
362-
tmp = t->tm_year - 100;
362+
tmp = t->tm_year % 100;
363363
regs[DS1307_REG_YEAR] = bin2bcd(tmp);
364364

365365
if (chip->century_enable_bit)

0 commit comments

Comments
 (0)