Commit 70d2a0ba authored by Wan ZongShun's avatar Wan ZongShun Committed by Linus Torvalds

rtc/nuc900: fix checking of args during time-setting

When a user application wants to set the rtc time, the RTC subsystem takes
advantage of 'rtc_valid_tm(tm)' to check 'rtc_time *tm' value validity, it
make sure the 'tm->tm_year' is larger than 70,so if '70< tm_year < 100',
the '(settm->tm_year - 100)' will be negative.  ' Setting the negative
value to hardware register will be invalid, so I add the 'if' condition to
make sure set a valid value to register.
Signed-off-by: default avatarWan ZongShun <mcuos.com@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0a89b553
...@@ -116,12 +116,18 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg, ...@@ -116,12 +116,18 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg,
rtc_valid_tm(tm); rtc_valid_tm(tm);
} }
static void nuc900_rtc_bin2bcd(struct rtc_time *settm, static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm,
struct nuc900_bcd_time *gettm) struct nuc900_bcd_time *gettm)
{ {
gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0;
gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8; gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8;
if (settm->tm_year < 100) {
dev_warn(dev, "The year will be between 1970-1999, right?\n");
gettm->bcd_year = bin2bcd(settm->tm_year) << 16;
} else {
gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16;
}
gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0;
gettm->bcd_min = bin2bcd(settm->tm_min) << 8; gettm->bcd_min = bin2bcd(settm->tm_min) << 8;
...@@ -176,7 +182,7 @@ static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -176,7 +182,7 @@ static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
unsigned long val; unsigned long val;
int *err; int *err;
nuc900_rtc_bin2bcd(tm, &gettm); nuc900_rtc_bin2bcd(dev, tm, &gettm);
err = check_rtc_access_enable(rtc); err = check_rtc_access_enable(rtc);
if (IS_ERR(err)) if (IS_ERR(err))
...@@ -211,7 +217,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -211,7 +217,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
unsigned long val; unsigned long val;
int *err; int *err;
nuc900_rtc_bin2bcd(&alrm->time, &tm); nuc900_rtc_bin2bcd(dev, &alrm->time, &tm);
err = check_rtc_access_enable(rtc); err = check_rtc_access_enable(rtc);
if (IS_ERR(err)) if (IS_ERR(err))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment