From 9b18f4a730a08026d2ddf24c6768fca8a60c4076 Mon Sep 17 00:00:00 2001 From: Kweh Hock Leong Date: Mon, 28 Mar 2022 14:12:53 +0800 Subject: [PATCH] net: gptp: Fix type mismatch calculation error in gptp_mi NSEC_PER_SEC is an unsigned integer macro. Thus, -NSEC_PER_SEC will be treated as unsigned integer as well which lead to calculation error on 64bits integer variables. Added the correct type casting into the formula to fix the calculation error. Signed-off-by: Kweh Hock Leong --- subsys/net/l2/ethernet/gptp/gptp_mi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/ethernet/gptp/gptp_mi.c b/subsys/net/l2/ethernet/gptp/gptp_mi.c index 0859868e8e3..12849add9c9 100644 --- a/subsys/net/l2/ethernet/gptp/gptp_mi.c +++ b/subsys/net/l2/ethernet/gptp/gptp_mi.c @@ -778,7 +778,7 @@ static void gptp_update_local_port_clock(void) if (second_diff < 0 && nanosecond_diff > 0) { second_diff++; - nanosecond_diff = -NSEC_PER_SEC + nanosecond_diff; + nanosecond_diff = -(int64_t)NSEC_PER_SEC + nanosecond_diff; } ptp_clock_rate_adjust(clk, port_ds->neighbor_rate_ratio);