aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorWan ZongShun <mcuos.com@gmail.com>2010-08-10 21:02:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-11 11:59:06 -0400
commit70d2a0bae26c7c44641785d9def8a0d9048abbea (patch)
tree01c89101b519340ff6252eb2de5024d016c20789 /drivers
parent0a89b55364e0a4fd4be9bc2c9a697f9b027eb395 (diff)
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: Wan ZongShun <mcuos.com@gmail.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/rtc/rtc-nuc900.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index 21d13309fb20..20bc70b472fb 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -116,12 +116,18 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg,
116 rtc_valid_tm(tm); 116 rtc_valid_tm(tm);
117} 117}
118 118
119static void nuc900_rtc_bin2bcd(struct rtc_time *settm, 119static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm,
120 struct nuc900_bcd_time *gettm) 120 struct nuc900_bcd_time *gettm)
121{ 121{
122 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; 122 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0;
123 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8; 123 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8;
124 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; 124
125 if (settm->tm_year < 100) {
126 dev_warn(dev, "The year will be between 1970-1999, right?\n");
127 gettm->bcd_year = bin2bcd(settm->tm_year) << 16;
128 } else {
129 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16;
130 }
125 131
126 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; 132 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0;
127 gettm->bcd_min = bin2bcd(settm->tm_min) << 8; 133 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 unsigned long val; 182 unsigned long val;
177 int *err; 183 int *err;
178 184
179 nuc900_rtc_bin2bcd(tm, &gettm); 185 nuc900_rtc_bin2bcd(dev, tm, &gettm);
180 186
181 err = check_rtc_access_enable(rtc); 187 err = check_rtc_access_enable(rtc);
182 if (IS_ERR(err)) 188 if (IS_ERR(err))
@@ -211,7 +217,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
211 unsigned long val; 217 unsigned long val;
212 int *err; 218 int *err;
213 219
214 nuc900_rtc_bin2bcd(&alrm->time, &tm); 220 nuc900_rtc_bin2bcd(dev, &alrm->time, &tm);
215 221
216 err = check_rtc_access_enable(rtc); 222 err = check_rtc_access_enable(rtc);
217 if (IS_ERR(err)) 223 if (IS_ERR(err))