[PATCH v2 2/2] rtc: ds1307: Clamp year to valid BCD (0-99) in `set_time()`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



`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@xxxxxxxxx>
Signed-off-by: Szentendrei, Tamás <szentendrei.tamas@xxxxxxxxx>
Signed-off-by: Csókás, Bence <csokas.bence@xxxxxxxxx>
---
 drivers/rtc/rtc-ds1307.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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)
-- 
2.34.1






[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux