Commit fd6792bb authored by Alexandre Belloni's avatar Alexandre Belloni
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: default avatarJon Hunter <jonathanh@nvidia.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent ca95ef7c
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -265,8 +265,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
			return err;
			return err;


		/* full-function RTCs won't have such missing fields */
		/* 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;
			return 0;
		}


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


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


	/* Make sure we're not setting alarms in the past */
	/* 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)
	 * over right here, before we set the alarm.
	 * over right here, before we set the alarm.
	 */
	 */


	rtc_subtract_offset(rtc, &alarm->time);

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


	mutex_unlock(&rtc->ops_lock);
	mutex_unlock(&rtc->ops_lock);


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