[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/24] rtc: Use time_t for passing and returning time offsets
From: |
Peter Maydell |
Subject: |
[PULL 21/24] rtc: Use time_t for passing and returning time offsets |
Date: |
Thu, 31 Aug 2023 11:45:16 +0100 |
The functions qemu_get_timedate() and qemu_timedate_diff() take
and return a time offset as an integer. Coverity points out that
means that when an RTC device implementation holds an offset
as a time_t, as the m48t59 does, the time_t will get truncated.
(CID 1507157, 1517772).
The functions work with time_t internally, so make them use that type
in their APIs.
Note that this won't help any Y2038 issues where either the device
model itself is keeping the offset in a 32-bit integer, or where the
hardware under emulation has Y2038 or other rollover problems. If we
missed any cases of the former then hopefully Coverity will warn us
about them since after this patch we'd be truncating a time_t in
assignments from qemu_timedate_diff().)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/sysemu/rtc.h | 4 ++--
softmmu/rtc.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/rtc.h b/include/sysemu/rtc.h
index 159702b45b5..0fc8ad6fdf1 100644
--- a/include/sysemu/rtc.h
+++ b/include/sysemu/rtc.h
@@ -42,7 +42,7 @@
* The behaviour of the clock whose value this function returns will
* depend on the -rtc command line option passed by the user.
*/
-void qemu_get_timedate(struct tm *tm, int offset);
+void qemu_get_timedate(struct tm *tm, time_t offset);
/**
* qemu_timedate_diff: Return difference between a struct tm and the RTC
@@ -53,6 +53,6 @@ void qemu_get_timedate(struct tm *tm, int offset);
* a timestamp one hour further ahead than the current RTC time
* then this function will return 3600.
*/
-int qemu_timedate_diff(struct tm *tm);
+time_t qemu_timedate_diff(struct tm *tm);
#endif
diff --git a/softmmu/rtc.c b/softmmu/rtc.c
index 4b2bf75dd67..4904581abeb 100644
--- a/softmmu/rtc.c
+++ b/softmmu/rtc.c
@@ -68,7 +68,7 @@ static time_t qemu_ref_timedate(QEMUClockType clock)
return value;
}
-void qemu_get_timedate(struct tm *tm, int offset)
+void qemu_get_timedate(struct tm *tm, time_t offset)
{
time_t ti = qemu_ref_timedate(rtc_clock);
@@ -85,7 +85,7 @@ void qemu_get_timedate(struct tm *tm, int offset)
}
}
-int qemu_timedate_diff(struct tm *tm)
+time_t qemu_timedate_diff(struct tm *tm)
{
time_t seconds;
--
2.34.1
- [PULL 03/24] target/arm: Support more GM blocksizes, (continued)
- [PULL 03/24] target/arm: Support more GM blocksizes, Peter Maydell, 2023/08/31
- [PULL 02/24] target/arm: Allow cpu to configure GM blocksize, Peter Maydell, 2023/08/31
- [PULL 07/24] target/arm: Apply access checks to neoverse-v1 special registers, Peter Maydell, 2023/08/31
- [PULL 06/24] target/arm: Apply access checks to neoverse-n1 special registers, Peter Maydell, 2023/08/31
- [PULL 09/24] target/arm: Implement FEAT_HPDS2 as a no-op, Peter Maydell, 2023/08/31
- [PULL 10/24] target/arm: properly document FEAT_CRC32, Peter Maydell, 2023/08/31
- [PULL 13/24] Add i.MX6UL missing devices., Peter Maydell, 2023/08/31
- [PULL 14/24] Refactor i.MX7 processor code, Peter Maydell, 2023/08/31
- [PULL 08/24] target/arm: Suppress FEAT_TRBE (Trace Buffer Extension), Peter Maydell, 2023/08/31
- [PULL 12/24] Refactor i.MX6UL processor code, Peter Maydell, 2023/08/31
- [PULL 21/24] rtc: Use time_t for passing and returning time offsets,
Peter Maydell <=
- [PULL 15/24] Add i.MX7 missing TZ devices and memory regions, Peter Maydell, 2023/08/31
- [PULL 16/24] Add i.MX7 SRC device implementation, Peter Maydell, 2023/08/31
- [PULL 24/24] hw/arm: Set number of MPU regions correctly for an505, an521, an524, Peter Maydell, 2023/08/31
- [PULL 23/24] hw/arm/armv7m: Add mpu-ns-regions and mpu-s-regions properties, Peter Maydell, 2023/08/31
- [PULL 17/24] target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS, Peter Maydell, 2023/08/31
- [PULL 18/24] hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm(), Peter Maydell, 2023/08/31
- [PULL 20/24] hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference, Peter Maydell, 2023/08/31
- [PULL 22/24] target/arm: Do all "ARM_FEATURE_X implies Y" checks in post_init, Peter Maydell, 2023/08/31
- [PULL 19/24] hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec, Peter Maydell, 2023/08/31
- [PULL 05/24] target/arm: Introduce make_ccsidr64, Peter Maydell, 2023/08/31