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

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>

authored by

Csókás, Bence and committed by
Alexandre Belloni
68f78c72 35a34f09

+1 -1
+1 -1
drivers/rtc/rtc-ds1307.c
··· 359 359 regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); 360 360 361 361 /* assume 20YY not 19YY */ 362 - tmp = t->tm_year - 100; 362 + tmp = t->tm_year % 100; 363 363 regs[DS1307_REG_YEAR] = bin2bcd(tmp); 364 364 365 365 if (chip->century_enable_bit)