diff mbox series

[v2] rtc: interface: Add RTC offset to alarm after fix-up

Message ID 20240619140451.2800578-1-csokas.bence@prolan.hu
State Accepted
Headers show
Series [v2] rtc: interface: Add RTC offset to alarm after fix-up | expand

Commit Message

Csókás, Bence June 19, 2024, 2:04 p.m. UTC
`rtc_add_offset()` is called by `__rtc_read_time()`
and `__rtc_read_alarm()` to add the RTC's offset to
the raw read-outs from the device drivers. However,
in the latter case, a fix-up algorithm is run if
the RTC device does not report a full `struct rtc_time`
alarm value. In that case, the offset was forgot to be
added.

Fixes: fd6792bb022e ("rtc: fix alarm read and set offset")

Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
---

Notes:
    Changes in v2:
    * don't try to add offset to an invalid tm

 drivers/rtc/interface.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Alexandre Belloni July 6, 2024, 10:34 p.m. UTC | #1
On Wed, 19 Jun 2024 16:04:52 +0200, Csókás, Bence wrote:
> `rtc_add_offset()` is called by `__rtc_read_time()`
> and `__rtc_read_alarm()` to add the RTC's offset to
> the raw read-outs from the device drivers. However,
> in the latter case, a fix-up algorithm is run if
> the RTC device does not report a full `struct rtc_time`
> alarm value. In that case, the offset was forgot to be
> added.
> 
> [...]

Applied, thanks!

[1/1] rtc: interface: Add RTC offset to alarm after fix-up
      https://git.kernel.org/abelloni/c/d506042ddcc8

Best regards,
diff mbox series

Patch

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 1b63111cdda2..0b23706d9fd3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -272,14 +272,13 @@  int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 		err = rtc_read_alarm_internal(rtc, alarm);
 		if (err)
 			return err;
 
 		/* full-function RTCs won't have such missing fields */
-		if (rtc_valid_tm(&alarm->time) == 0) {
-			rtc_add_offset(rtc, &alarm->time);
-			return 0;
-		}
+		err = rtc_valid_tm(&alarm->time);
+		if (!err)
+			goto done;
 
 		/* get the "after" timestamp, to detect wrapped fields */
 		err = rtc_read_time(rtc, &now);
 		if (err < 0)
 			return err;
@@ -377,10 +376,12 @@  int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 
 done:
 	if (err && alarm->enabled)
 		dev_warn(&rtc->dev, "invalid alarm value: %ptR\n",
 			 &alarm->time);
+	else
+		rtc_add_offset(rtc, &alarm->time);
 
 	return err;
 }
 
 int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)