patch-2.3.41 linux/arch/m68k/mvme16x/rtc.c

Next file: linux/arch/m68k/sun3/Makefile
Previous file: linux/arch/m68k/mvme16x/mvme16x_ksyms.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.40/linux/arch/m68k/mvme16x/rtc.c linux/arch/m68k/mvme16x/rtc.c
@@ -67,8 +67,9 @@
 	}
 	case RTC_SET_TIME:	/* Set the RTC */
 	{
-		unsigned char leap_yr;
 		struct rtc_time rtc_tm;
+		unsigned char mon, day, hrs, min, sec, leap_yr;
+		unsigned int yrs;
 
 		if (!suser())
 			return -EACCES;
@@ -77,31 +78,41 @@
 				   sizeof(struct rtc_time)))
 			return -EFAULT;
 
-		leap_yr = ((!(rtc_tm.tm_year % 4) && (rtc_tm.tm_year % 100)) || !(rtc_tm.tm_year % 400));
+		yrs = rtc_tm.tm_year;
+		if (yrs < 1900)
+			yrs += 1900;
+		mon = rtc_tm.tm_mon + 1;   /* tm_mon starts at zero */
+		day = rtc_tm.tm_mday;
+		hrs = rtc_tm.tm_hour;
+		min = rtc_tm.tm_min;
+		sec = rtc_tm.tm_sec;
 
-		if ((rtc_tm.tm_mon > 12) || (rtc_tm.tm_mday == 0))
+		leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400));
+
+		if ((mon > 12) || (day == 0))
 			return -EINVAL;
 
-		if (rtc_tm.tm_mday > (days_in_mo[rtc_tm.tm_mon] + ((rtc_tm.tm_mon == 2) && leap_yr)))
+		if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr)))
 			return -EINVAL;
-			
-		if ((rtc_tm.tm_hour >= 24) || (rtc_tm.tm_min >= 60) || (rtc_tm.tm_sec >= 60))
+
+		if ((hrs >= 24) || (min >= 60) || (sec >= 60))
 			return -EINVAL;
 
+		if (yrs >= 2070)
+			return -EINVAL;
+		
 		save_flags(flags);
 		cli();
-		rtc->ctrl = RTC_WRITE;
+		rtc->ctrl     = RTC_WRITE;
 
-		rtc->bcd_sec = BIN2BCD(rtc_tm.tm_sec);
-		rtc->bcd_min = BIN2BCD(rtc_tm.tm_min);
-		rtc->bcd_hr  = BIN2BCD(rtc_tm.tm_hour);
-		rtc->bcd_dom = BIN2BCD(rtc_tm.tm_mday);
-		rtc->bcd_mth = BIN2BCD(rtc_tm.tm_mon + 1);
-		rtc->bcd_year = BIN2BCD(rtc_tm.tm_year%100);
-		if (rtc_tm.tm_wday >= 0)
-			rtc->bcd_dow = BIN2BCD(rtc_tm.tm_wday+1);
+		rtc->bcd_sec  = BIN2BCD(sec);
+		rtc->bcd_min  = BIN2BCD(min);
+		rtc->bcd_hr   = BIN2BCD(hrs);
+		rtc->bcd_dom  = BIN2BCD(day);
+		rtc->bcd_mth  = BIN2BCD(mon);
+		rtc->bcd_year = BIN2BCD(yrs%100);
 
-		rtc->ctrl = 0;
+		rtc->ctrl     = 0;
 		restore_flags(flags);
 		return 0;
 	}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)