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

Next file: linux/arch/m68k/config.in
Previous file: linux/arch/m68k/bvme6000/config.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.40/linux/arch/m68k/bvme6000/rtc.c linux/arch/m68k/bvme6000/rtc.c
@@ -71,8 +71,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;
@@ -81,34 +82,46 @@
 				   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();
 		/* Ensure clock and real-time-mode-register are accessible */
 		msr = rtc->msr & 0xc0;
 		rtc->msr = 0x40;
 
-		rtc->t0cr_rtmr = rtc_tm.tm_year%4;
+		rtc->t0cr_rtmr = yrs%4;
 		rtc->bcd_tenms = 0;
-		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);
+		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);
 		if (rtc_tm.tm_wday >= 0)
 			rtc->bcd_dow = BIN2BCD(rtc_tm.tm_wday+1);
-		rtc->t0cr_rtmr = rtc_tm.tm_year%4 | 0x08;
+		rtc->t0cr_rtmr = yrs%4 | 0x08;
 
 		rtc->msr = msr;
 		restore_flags(flags);

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