Skip to content

Commit 47e10a6

Browse files
mniestrojcfriedt
authored andcommitted
drivers: lora: fix RtcGetCalendarTime()
Uptime in milliseconds is assigned to uint32_t variable, which results in integer overflow after enough time has expired. Additionally milliseconds part (which should be 0-999) is assigned directly from uptime, without subtracting full seconds. Fix both issues by using int64_t variable and calculating milliseconds with modulo. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent ed55ee9 commit 47e10a6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/lora/hal_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void RtcBkupRead(uint32_t *data0, uint32_t *data1)
4343

4444
uint32_t RtcGetCalendarTime(uint16_t *milliseconds)
4545
{
46-
uint32_t now = k_uptime_get_32();
46+
int64_t now = k_uptime_get();
4747

48-
*milliseconds = now;
48+
*milliseconds = now % MSEC_PER_SEC;
4949

5050
/* Return in seconds */
5151
return now / MSEC_PER_SEC;

0 commit comments

Comments
 (0)