summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCsókás, Bence <csokas.bence@prolan.hu>2024-06-11 09:24:09 +0200
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2024-07-07 00:39:27 +0200
commit68f78c720da4088d254250867126c6ae5b68fa2a (patch)
tree5425be29a73dd50445d0e490cd39cad7c01f10f8
parent35a34f09baed51216455740e01bd132cf60c71cf (diff)
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>
-rw-r--r--drivers/rtc/rtc-ds1307.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bdb7b201a160..872e0b679be4 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -359,7 +359,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);
/* assume 20YY not 19YY */
- tmp = t->tm_year - 100;
+ tmp = t->tm_year % 100;
regs[DS1307_REG_YEAR] = bin2bcd(tmp);
if (chip->century_enable_bit)