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 <szentendrei.tamas@prolan.hu> Signed-off-by: Szentendrei, Tamás <szentendrei.tamas@prolan.hu> Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu> Link: https://lore.kernel.org/r/20240611072411.671600-2-csokas.bence@prolan.hu Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 35a34f0 commit 68f78c7

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

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)