From b3505fbaa69add53bf2e7874371973c17232ef05 Mon Sep 17 00:00:00 2001 From: Tomas Choat Date: Tue, 26 Nov 2024 10:38:15 +0100 Subject: [PATCH] net: lib: ptp: Fix bidir time adjustment When the offset is larger than 1 second, the time adjustment should still be allowed to be bidirectional. Casting the offset to an unsigned value after the subtraction will allow the adjustment to be bidirectional. Signed-off-by: Tomas Choat --- subsys/net/lib/ptp/clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/ptp/clock.c b/subsys/net/lib/ptp/clock.c index 2db8d1366ad..c88edffacfd 100644 --- a/subsys/net/lib/ptp/clock.c +++ b/subsys/net/lib/ptp/clock.c @@ -529,8 +529,8 @@ void ptp_clock_synchronize(uint64_t ingress, uint64_t egress) ptp_clock_get(ptp_clk.phc, ¤t); - current.second -= (uint64_t)(offset / NSEC_PER_SEC); - dest_nsec = (int32_t)(current.nanosecond - (uint32_t)(offset % NSEC_PER_SEC)); + current.second = (uint64_t)(current.second - (offset / NSEC_PER_SEC)); + dest_nsec = (int32_t)(current.nanosecond - (offset % NSEC_PER_SEC)); if (dest_nsec < 0) { current.second--;