This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 39400bfd028d338b6457585d9c356bdf1fcf75f4
Author: huojianchao <[email protected]>
AuthorDate: Fri Dec 19 18:25:13 2025 +0800

    drivers/timers/pl031: clear tm_nsec in pl031_rdtime()
    
    pl031_rdtime() fills struct rtc_time with gmtime_r(), which only sets
    the struct tm fields.  With CONFIG_RTC_HIRES or
    CONFIG_ARCH_HAVE_RTC_SUBSECONDS, struct rtc_time also has tm_nsec, and
    it kept whatever the caller had there: RTC_RD_TIME returned the old
    value of the caller's buffer, and an RPMsg RTC server on top of the
    PL031 sent the stack garbage of the local struct rtc_time of
    rpmsg_rtc_server_sync() to its clients.
    
    The PL031 only counts whole seconds, so set tm_nsec to 0.
    
    Signed-off-by: huojianchao <[email protected]>
---
 drivers/timers/pl031.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/timers/pl031.c b/drivers/timers/pl031.c
index 38aaa4a0a8f..a91dd3ffb2b 100644
--- a/drivers/timers/pl031.c
+++ b/drivers/timers/pl031.c
@@ -129,6 +129,9 @@ static int pl031_rdtime(FAR struct rtc_lowerhalf_s *lower,
   time = pl031_getreg(priv->base, PL031_RTCDR);
 
   gmtime_r(&time, (FAR struct tm *)rtctime);
+#if defined(CONFIG_RTC_HIRES) || defined(CONFIG_ARCH_HAVE_RTC_SUBSECONDS)
+  rtctime->tm_nsec = 0;
+#endif
 
   return 0;
 }

Reply via email to