From: Csókás, Bence Date: Tue, 11 Jun 2024 07:24:09 +0000 (+0200) Subject: rtc: ds1307: Clamp year to valid BCD (0-99) in `set_time()` X-Git-Tag: v6.11-rc1~86^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68f78c720da4088d254250867126c6ae5b68fa2a;p=thirdparty%2Flinux.git 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 Signed-off-by: Szentendrei, Tamás Signed-off-by: Csókás, Bence Link: https://lore.kernel.org/r/20240611072411.671600-2-csokas.bence@prolan.hu Signed-off-by: Alexandre Belloni --- diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index bdb7b201a1605..872e0b679be48 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)