summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorPreetham Chandru <pchandru@nvidia.com>2012-07-20 11:01:26 +0530
committerVarun Wadekar <vwadekar@nvidia.com>2012-07-30 16:25:58 +0530
commit9b667813cf7593fd783cf52e33244c497ca3a354 (patch)
tree747f6129a88ce0370e266dc913215ad561bd5032 /drivers/rtc
parentfb4075179a6d663cf185d3bbfaa6e9a7638cc922 (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 037e456d7437..a587dda28015 100644
--- a/drivers/rtc/rtc-tps6591x.c
+++ b/drivers/rtc/rtc-tps6591x.c
@@ -107,6 +107,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)
@@ -246,6 +247,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;
@@ -324,6 +331,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);
@@ -462,13 +475,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);
}