rtc: ams3722: Fix setting alarm time in the past
Kamal Kannan Balagopalan [Mon, 17 Jun 2013 22:55:51 +0000 (15:55 -0700)]
Alarm year was manipulated incorrectly and alarm set returned error
as alarm year was in the past. This also caused suspend entry to
exit abnormally.

Bug 1284096

Change-Id: Id6ade9949dd29e5b866c78fbf053e1c5048c1c6e
Signed-off-by: Kamal Kannan Balagopalan <kbalagopalan@nvidia.com>
Reviewed-on: http://git-master/r/239442
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>

drivers/rtc/rtc-as3722.c

index 7b05ac1..ab03a68 100644 (file)
@@ -95,10 +95,11 @@ static int as3722_rtc_settime(struct device *dev, struct rtc_time *tm)
                        + (tm->tm_mday % 10);
        as_time_array[4] = ((tm->tm_mon / 10) << 4)
                        + (tm->tm_mon % 10);
-       if (tm->tm_year > AS3722_RTC_START_YEAR)
-               as_time_array[5] = (((tm->tm_year - AS3722_RTC_START_YEAR)
-                               / 10) << 4)
-                               + ((tm->tm_year - AS3722_RTC_START_YEAR) % 10);
+       if (tm->tm_year >= (AS3722_RTC_START_YEAR - 1900))
+               as_time_array[5] = (((tm->tm_year
+                               - (AS3722_RTC_START_YEAR - 1900)) / 10) << 4)
+                               + ((tm->tm_year
+                               - (AS3722_RTC_START_YEAR - 1900)) % 10);
        else
                return -1;
 
@@ -156,11 +157,11 @@ static int as3722_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
                        + (alrm->time.tm_mday % 10);
        as_time_array[4] = ((alrm->time.tm_mon / 10) << 4)
                        + (alrm->time.tm_mon % 10);
-       if (alrm->time.tm_year > AS3722_RTC_START_YEAR)
-               as_time_array[5] =
-                       (((alrm->time.tm_year - AS3722_RTC_START_YEAR)
-                       / 10) << 4)
-                       + ((alrm->time.tm_year - AS3722_RTC_START_YEAR) % 10);
+       if (alrm->time.tm_year >= (AS3722_RTC_START_YEAR - 1900))
+               as_time_array[5] = (((alrm->time.tm_year
+                               - (AS3722_RTC_START_YEAR - 1900)) / 10) << 4)
+                               + ((alrm->time.tm_year
+                               - (AS3722_RTC_START_YEAR - 1900)) % 10);
        else
                return -1;