Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
rtc: fix alarm read and set offset
Browse files Browse the repository at this point in the history
The offset needs to be added after reading the alarm value.

It also needs to be subtracted after the now < alarm test.

Tested-by: Jon Hunter <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
  • Loading branch information
alexandrebelloni committed Jul 13, 2018
1 parent ca95ef7 commit fd6792b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/rtc/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
return err;

/* full-function RTCs won't have such missing fields */
if (rtc_valid_tm(&alarm->time) == 0)
if (rtc_valid_tm(&alarm->time) == 0) {
rtc_add_offset(rtc, &alarm->time);
return 0;
}

/* get the "after" timestamp, to detect wrapped fields */
err = rtc_read_time(rtc, &now);
Expand Down Expand Up @@ -409,7 +411,6 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
if (err)
return err;

rtc_subtract_offset(rtc, &alarm->time);
scheduled = rtc_tm_to_time64(&alarm->time);

/* Make sure we're not setting alarms in the past */
Expand All @@ -426,6 +427,8 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
* over right here, before we set the alarm.
*/

rtc_subtract_offset(rtc, &alarm->time);

if (!rtc->ops)
err = -ENODEV;
else if (!rtc->ops->set_alarm)
Expand Down Expand Up @@ -467,7 +470,6 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)

mutex_unlock(&rtc->ops_lock);

rtc_add_offset(rtc, &alarm->time);
return err;
}
EXPORT_SYMBOL_GPL(rtc_set_alarm);
Expand Down

0 comments on commit fd6792b

Please sign in to comment.