Skip to content

Commit fd6792b

Browse files
rtc: fix alarm read and set offset
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 <jonathanh@nvidia.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent ca95ef7 commit fd6792b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/rtc/interface.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
265265
return err;
266266

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

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

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

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

430+
rtc_subtract_offset(rtc, &alarm->time);
431+
429432
if (!rtc->ops)
430433
err = -ENODEV;
431434
else if (!rtc->ops->set_alarm)
@@ -467,7 +470,6 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
467470

468471
mutex_unlock(&rtc->ops_lock);
469472

470-
rtc_add_offset(rtc, &alarm->time);
471473
return err;
472474
}
473475
EXPORT_SYMBOL_GPL(rtc_set_alarm);

0 commit comments

Comments
 (0)