Browse Source

implement check for dates before 2000 for DS1307

Helmut Pozimski 5 years ago
parent
commit
0e2568fa86
1 changed files with 3 additions and 0 deletions
  1. 3 0
      rtc-ds13307.c

+ 3 - 0
rtc-ds13307.c

@@ -155,6 +155,9 @@ static int ds13307_set_time(struct device *dev, struct rtc_time *time) {
 	buf[5] = bin2bcd(time->tm_mday);
 	if ((model_detected == DEVICE_DS1337) && (time->tm_year >= 100)) {
 		buf[6] = bin2bcd(time->tm_mon + 1) | COMMON_HIGH_BIT;
+	} else if ((model_detected == DEVICE_DS1307) && (time->tm_year < 100)) {
+		       printk(KERN_ERR "%s: device does not support century information, dates before 2000 are not possible\n", M_NAME);
+		       return -EINVAL;
 	} else {
 		buf[6] = bin2bcd(time->tm_mon + 1);
 	}