git: 0eda98025d37 - stable/13 - goldfish_rtc: Fix handling a local time RTC

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Tue, 31 Jan 2023 01:51:53 UTC
The branch stable/13 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=0eda98025d37f2546722c1256074062f3b93a5c0

commit 0eda98025d37f2546722c1256074062f3b93a5c0
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2022-08-14 18:50:22 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-01-31 01:50:27 +0000

    goldfish_rtc: Fix handling a local time RTC
    
    The default QEMU config is to have the RTC in UTC. However, if run with
    -rtc base=localtime (and wall_cmos_clock is set to match), the driver
    fails to account for adjkerntz due to the use of CLOCKF_SETTIME_NO_ADJ.
    Copy the same code used by other CLOCKF_SETTIME_NO_ADJ-using drivers
    to fix this, namely manually subtracting utc_offset().
    
    Fixes:          d63a631e7244 ("Add Goldfish RTC device driver for RISC-V")
    MFC after:      1 week
    
    (cherry picked from commit 762dcf10641251c55dda2e6950fef8bb698027ad)
---
 sys/dev/goldfish/goldfish_rtc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/dev/goldfish/goldfish_rtc.c b/sys/dev/goldfish/goldfish_rtc.c
index d1c2b6627ae2..081ea37bb8ef 100644
--- a/sys/dev/goldfish/goldfish_rtc.c
+++ b/sys/dev/goldfish/goldfish_rtc.c
@@ -151,6 +151,11 @@ goldfish_rtc_settime(device_t dev, struct timespec *ts)
 
 	sc = device_get_softc(dev);
 
+	/*
+	 * We request a timespec with no resolution-adjustment.  That also
+	 * disables utc adjustment, so apply that ourselves.
+	 */
+	ts->tv_sec -= utc_offset();
 	nsec = (uint64_t)ts->tv_sec * 1000000000 + ts->tv_nsec;
 
 	mtx_lock(&sc->mtx);