]> Git Repo - linux.git/commitdiff
rtc: ds1307: Clamp year to valid BCD (0-99) in `set_time()`
authorCsókás, Bence <[email protected]>
Tue, 11 Jun 2024 07:24:09 +0000 (09:24 +0200)
committerAlexandre Belloni <[email protected]>
Sat, 6 Jul 2024 22:39:27 +0000 (00:39 +0200)
`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]>
drivers/rtc/rtc-ds1307.c

index bdb7b201a1605e345690f61b522a6c1af09e194f..872e0b679be4814f3108bae35395a17f5bfcd63c 100644 (file)
@@ -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)
This page took 0.063709 seconds and 4 git commands to generate.