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 <trc@ixys.no>
This commit is contained in:
Tomas Choat 2024-11-26 10:38:15 +01:00 committed by Benjamin Cabé
commit b3505fbaa6

View file

@ -529,8 +529,8 @@ void ptp_clock_synchronize(uint64_t ingress, uint64_t egress)
ptp_clock_get(ptp_clk.phc, &current);
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--;