From 7038b6e4e71d9fb3a234e00da31c222d3e97dd5c Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 31 Aug 2023 09:45:17 +0100 Subject: hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the m48t59 device we almost always use 64-bit arithmetic when dealing with time_t deltas. The one exception is in set_alarm(), which currently uses a plain 'int' to hold the difference between two time_t values. Switch to int64_t instead to avoid any possible overflow issues. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/rtc/m48t59.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/rtc') diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c index ec3e56e84f..2e2c849985 100644 --- a/hw/rtc/m48t59.c +++ b/hw/rtc/m48t59.c @@ -133,7 +133,7 @@ static void alarm_cb (void *opaque) static void set_alarm(M48t59State *NVRAM) { - int diff; + int64_t diff; if (NVRAM->alrm_timer != NULL) { timer_del(NVRAM->alrm_timer); diff = qemu_timedate_diff(&NVRAM->alarm) - NVRAM->time_offset; -- cgit v1.2.3 From 279695a4a4472c41d8764317e4fae04d93ee2b42 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 31 Aug 2023 09:45:18 +0100 Subject: hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the twl92230 device, use int64_t for the two state fields sec_offset and alm_sec, because we set these to values that are either time_t or differences between two time_t values. These fields aren't saved in vmstate anywhere, so we can safely widen them. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/rtc/twl92230.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw/rtc') diff --git a/hw/rtc/twl92230.c b/hw/rtc/twl92230.c index d8534dad94..64c61c3dae 100644 --- a/hw/rtc/twl92230.c +++ b/hw/rtc/twl92230.c @@ -65,8 +65,8 @@ struct MenelausState { struct tm tm; struct tm new; struct tm alm; - int sec_offset; - int alm_sec; + int64_t sec_offset; + int64_t alm_sec; int next_comp; } rtc; uint16_t rtc_next_vmstate; -- cgit v1.2.3 From c0a63857282afebaeed606a3dca803bb3bfb6aa3 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 31 Aug 2023 09:45:18 +0100 Subject: hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the aspeed_rtc device we store a difference between two time_t values in an 'int'. This is not really correct when time_t could be 64 bits. Enlarge the field to 'int64_t'. This is a migration compatibility break for the aspeed boards. While we are changing the vmstate, remove the accidental duplicate of the offset field. Signed-off-by: Peter Maydell Reviewed-by: Cédric Le Goater --- hw/rtc/aspeed_rtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'hw/rtc') diff --git a/hw/rtc/aspeed_rtc.c b/hw/rtc/aspeed_rtc.c index f6da7b666d..fa861e2d49 100644 --- a/hw/rtc/aspeed_rtc.c +++ b/hw/rtc/aspeed_rtc.c @@ -136,11 +136,10 @@ static const MemoryRegionOps aspeed_rtc_ops = { static const VMStateDescription vmstate_aspeed_rtc = { .name = TYPE_ASPEED_RTC, - .version_id = 1, + .version_id = 2, .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(reg, AspeedRtcState, 0x18), - VMSTATE_INT32(offset, AspeedRtcState), - VMSTATE_INT32(offset, AspeedRtcState), + VMSTATE_INT64(offset, AspeedRtcState), VMSTATE_END_OF_LIST() } }; -- cgit v1.2.3