summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorPreetham Chandru <pchandru@nvidia.com>2012-07-20 11:01:26 +0530
committerLokesh Pathak <lpathak@nvidia.com>2012-07-26 04:46:03 -0700
commit9b30c9e8b7c3ec08f56a610644491125690e9ef2 (patch)
treefc153c510d6bbe65b6da3a7973a615a5748e24ba /drivers/rtc
parentf30664a1e3cecbea4ab242727d0cb5fd71a97bf4 (diff)
rtc: tps6591x: Prevent wrong date setting
This CL handles the following: 1. Prevents setting of wrong date in tps6591x_rtc_set_time(). For example the following case was not handled in rtc driver: if hwclock command wanted to set 31/Dec/1999 then our RTC driver was setting the date to 31/Dec/2099 and later on when hwclock read the date back it was getting a invalid date. Also, the hwclock command can only handle date upto the year 2038. 2. Sets STOP_RTC bit to one when the driver is initialized Bug 1012914 Bug 1017647 Signed-off-by: Preetham Chandru R <pchandru@nvidia.com> Change-Id: If8abfebe3ee6da05498deb38d7247ab265729c0c Reviewed-on: http://git-master/r/117298 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Venu Byravarasu <vbyravarasu@nvidia.com> Reviewed-by: Kiran Adduri <kadduri@nvidia.com> Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-tps6591x.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/drivers/rtc/rtc-tps6591x.c b/drivers/rtc/rtc-tps6591x.c
index ebc46b4cf46e..9644dc4afb42 100644
--- a/drivers/rtc/rtc-tps6591x.c
+++ b/drivers/rtc/rtc-tps6591x.c
@@ -106,6 +106,7 @@ static int tps6591x_write_regs(struct device *dev, int reg, int len,
static int tps6591x_rtc_valid_tm(struct rtc_time *tm)
{
if (tm->tm_year >= (RTC_YEAR_OFFSET + 99)
+ || tm->tm_year < (RTC_YEAR_OFFSET)
|| tm->tm_mon >= 12
|| tm->tm_mday < 1
|| tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + OS_REF_YEAR)
@@ -245,6 +246,12 @@ static int tps6591x_rtc_set_time(struct device *dev, struct rtc_time *tm)
u8 buff[7];
int err;
+ err = tps6591x_rtc_valid_tm(tm);
+ if (err < 0) {
+ dev_err(dev->parent, "\n Invalid Time\n");
+ return err;
+ }
+
buff[0] = tm->tm_sec;
buff[1] = tm->tm_min;
buff[2] = tm->tm_hour;
@@ -323,6 +330,12 @@ static int tps6591x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
if (rtc->irq == -1)
return -EIO;
+ err = tps6591x_rtc_valid_tm(&alrm->time);
+ if (err < 0) {
+ dev_err(dev->parent, "\n Invalid alarm time\n");
+ return err;
+ }
+
dev_info(dev->parent, "\n setting alarm to requested time::\n");
print_time(dev->parent, &alrm->time);
rtc_tm_to_time(&alrm->time, &seconds);
@@ -461,13 +474,20 @@ static int __devinit tps6591x_rtc_probe(struct platform_device *pdev)
return -EBUSY;
}
+ err = tps6591x_rtc_start(&pdev->dev);
+ if (err) {
+ dev_err(&pdev->dev, "unable to start RTC\n");
+ return -EBUSY;
+ }
+
tps6591x_rtc_read_time(&pdev->dev, &tm);
- if ((tm.tm_year < RTC_YEAR_OFFSET || tm.tm_year > (RTC_YEAR_OFFSET + 99))){
- if (pdata->time.tm_year < 2000 || pdata->time.tm_year > 2100) {
+
+ if (tps6591x_rtc_valid_tm(&tm) < 0) {
+ if (pdata->time.tm_year < 2000 || pdata->time.tm_year >= 2100) {
memset(&pdata->time, 0, sizeof(pdata->time));
- pdata->time.tm_year = RTC_YEAR_OFFSET;
+ pdata->time.tm_year = 2000;
pdata->time.tm_mday = 1;
- } else
+ }
pdata->time.tm_year -= OS_REF_YEAR;
tps6591x_rtc_set_time(&pdev->dev, &pdata->time);
}