summaryrefslogtreecommitdiffstats
path: root/arch/m68k/mvme16x/rtc.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/m68k/mvme16x/rtc.c')
-rw-r--r--arch/m68k/mvme16x/rtc.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/arch/m68k/mvme16x/rtc.c b/arch/m68k/mvme16x/rtc.c
index 75efb8bd6..f5f472132 100644
--- a/arch/m68k/mvme16x/rtc.c
+++ b/arch/m68k/mvme16x/rtc.c
@@ -67,8 +67,9 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
}
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 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
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;
}