Linux RTC
 help / color / mirror / Atom feed
* [PATCH] drivers: rtc: handle OTF clock changes
@ 2026-06-24 12:31 Elad Nachman
  2026-06-24 15:31 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Elad Nachman @ 2026-06-24 12:31 UTC (permalink / raw)
  To: alexandre.belloni, linux-rtc, linux-kernel; +Cc: enachman

From: Elad Nachman <enachman@marvell.com>

When processing expired RTC events and rearming them, use now
instead of expiry to prevent endless loops.
Issue seen with Armada 385 SOC.

Fixes commit 6610e0893b8b ("RTC: Rework RTC code to use timerqueue for events")
Signed-off-by: Elad Nachman <enachman@marvell.com>
---
 drivers/rtc/interface.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 96626f8068f9..c32ef95a07d4 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -126,6 +126,7 @@ EXPORT_SYMBOL_GPL(rtc_read_time);
 int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 {
 	int err, uie;
+	struct rtc_time new_tm;
 
 	err = rtc_valid_tm(tm);
 	if (err != 0)
@@ -159,6 +160,17 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 	else
 		err = -EINVAL;
 
+	if (rtc && rtc->ops && rtc->ops->read_time) {
+		if (!rtc->ops->read_time(rtc->dev.parent, &new_tm)) {
+			pr_debug("new rtc time secs %d mins %d hours %d mday %d mon %d year %d way %d yday %d dst %d\n",
+					new_tm.tm_sec, new_tm.tm_min,
+					new_tm.tm_hour, new_tm.tm_mday,
+					new_tm.tm_mon, new_tm.tm_year,
+					new_tm.tm_wday, new_tm.tm_yday,
+					new_tm.tm_isdst);
+		}
+	}
+
 	pm_stay_awake(rtc->dev.parent);
 	mutex_unlock(&rtc->ops_lock);
 	/* A timer might have just expired */
@@ -999,7 +1011,7 @@ void rtc_timer_do_work(struct work_struct *work)
 		trace_rtc_timer_fired(timer);
 		/* Re-add/fwd periodic timers */
 		if (ktime_to_ns(timer->period)) {
-			timer->node.expires = ktime_add(timer->node.expires,
+			timer->node.expires = ktime_add(now,
 							timer->period);
 			timer->enabled = 1;
 			timerqueue_add(&rtc->timerqueue, &timer->node);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers: rtc: handle OTF clock changes
  2026-06-24 12:31 [PATCH] drivers: rtc: handle OTF clock changes Elad Nachman
@ 2026-06-24 15:31 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2026-06-24 15:31 UTC (permalink / raw)
  To: Elad Nachman; +Cc: linux-rtc, linux-kernel

On 24/06/2026 15:31:03+0300, Elad Nachman wrote:
> From: Elad Nachman <enachman@marvell.com>
> 
> When processing expired RTC events and rearming them, use now
> instead of expiry to prevent endless loops.
> Issue seen with Armada 385 SOC.

The loop is not endless, it may be long however. How do you reproduce
this? Or maybe the question is what is enabling PIE on your system?

Your patch breaks existing code because it will expect to get one event
per elapsed period while your patch will cause events to be skipped.

> 
> Fixes commit 6610e0893b8b ("RTC: Rework RTC code to use timerqueue for events")
> Signed-off-by: Elad Nachman <enachman@marvell.com>
> ---
>  drivers/rtc/interface.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 96626f8068f9..c32ef95a07d4 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -126,6 +126,7 @@ EXPORT_SYMBOL_GPL(rtc_read_time);
>  int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
>  {
>  	int err, uie;
> +	struct rtc_time new_tm;
>  
>  	err = rtc_valid_tm(tm);
>  	if (err != 0)
> @@ -159,6 +160,17 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
>  	else
>  		err = -EINVAL;
>  
> +	if (rtc && rtc->ops && rtc->ops->read_time) {
> +		if (!rtc->ops->read_time(rtc->dev.parent, &new_tm)) {
> +			pr_debug("new rtc time secs %d mins %d hours %d mday %d mon %d year %d way %d yday %d dst %d\n",
> +					new_tm.tm_sec, new_tm.tm_min,
> +					new_tm.tm_hour, new_tm.tm_mday,
> +					new_tm.tm_mon, new_tm.tm_year,
> +					new_tm.tm_wday, new_tm.tm_yday,
> +					new_tm.tm_isdst);
> +		}
> +	}
> +


This is unrelated to the patch.

>  	pm_stay_awake(rtc->dev.parent);
>  	mutex_unlock(&rtc->ops_lock);
>  	/* A timer might have just expired */
> @@ -999,7 +1011,7 @@ void rtc_timer_do_work(struct work_struct *work)
>  		trace_rtc_timer_fired(timer);
>  		/* Re-add/fwd periodic timers */
>  		if (ktime_to_ns(timer->period)) {
> -			timer->node.expires = ktime_add(timer->node.expires,
> +			timer->node.expires = ktime_add(now,
>  							timer->period);
>  			timer->enabled = 1;
>  			timerqueue_add(&rtc->timerqueue, &timer->node);
> -- 
> 2.25.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-24 15:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 12:31 [PATCH] drivers: rtc: handle OTF clock changes Elad Nachman
2026-06-24 15:31 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox