|SUCCESS| [v3] net/idpf: harden PTP frequency adjustment

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Wed May 6 16:25:33 CEST 2026


Test-Label: ai-code-review
Test-Status: SUCCESS
https://dpdk.org/patch/163654

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-05-06

git sha: series.patch
Author: Soumyadeep Hore <soumyadeep.hore at intel.com>
Subject: [PATCH v3] net/idpf: harden PTP frequency adjustment

This patch refactors the PTP frequency adjustment calculation to use
native __int128 arithmetic on 64-bit builds while maintaining a portable
split-and-scale approach for 32-bit builds. The change addresses a
Coverity issue (501832) related to INT64_MIN negation.

> diff --git a/drivers/net/intel/idpf/idpf_ethdev.c b/drivers/net/intel/idpf/idpf_ethdev.c
> index 5e57a45775..31291379d3 100644
> --- a/drivers/net/intel/idpf/idpf_ethdev.c
> +++ b/drivers/net/intel/idpf/idpf_ethdev.c
> @@ -1005,42 +1005,64 @@ idpf_timesync_adjust_freq(struct rte_eth_dev *dev, int64_t ppm)
>  	struct idpf_vport *vport = dev->data->dev_private;
>  	struct idpf_adapter *adapter = vport->adapter;
>  	struct idpf_ptp *ptp = adapter->ptp;
> -	int64_t incval, diff = 0;
> -	bool negative = false;
> -	uint64_t div, rem;
> -	uint64_t divisor = 1000000ULL << 16;
> -	int shift;
> +	uint64_t incval;
>  	int ret;
>  
>  	incval = ptp->base_incval;

Does this code preserve the signedness intent of base_incval? The
original used int64_t incval, but here incval is changed to uint64_t.
If base_incval can be negative or if signed arithmetic matters in the
adjustment, could this type change introduce unintended behavior?

[ ... ]

> +#ifdef RTE_ARCH_64
> +	/* ppm is scaled by 2^16 to match Linux adjfine. */
> +	{
> +		__int128 diff;
> +
> +		diff = ((__int128)incval * ppm) / (1000000LL << 16);
> +		incval += (int64_t)diff;
> +	}
> +#else
> +	{
> +		int64_t diff = 0;
> +		bool negative = false;
> +		uint64_t abs_ppm, div, rem;
> +		uint64_t divisor = 1000000ULL << 16;
> +		int shift;
> +
> +		if (ppm < 0) {
> +			negative = true;
> +			abs_ppm = ppm == INT64_MIN ? (uint64_t)INT64_MAX + 1 :
> +				(uint64_t)(-ppm);

Does this conditional handle the conversion correctly on all compilers?
The expression (uint64_t)INT64_MAX + 1 depends on wrapping behavior. Is
there an explicit guarantee that this produces the correct absolute value
for INT64_MIN?

> +		} else {
> +			abs_ppm = (uint64_t)ppm;
> +		}
> +
> +		/* can incval * ppm overflow ? */
> +		if (rte_log2_u64(incval) + rte_log2_u64(abs_ppm) > 62) {
> +			rem = abs_ppm % divisor;
> +			div = abs_ppm / divisor;
> +			diff = div * incval;
> +			abs_ppm = rem;
> +
> +			if (abs_ppm != 0) {
> +				uint32_t log_sum;
> +
> +				log_sum = rte_log2_u64(incval) + rte_log2_u64(abs_ppm);

Is there a concern about abs_ppm being zero at this point? The outer
if (abs_ppm != 0) should guard this, but could there be edge cases where
abs_ppm becomes zero between the assignment abs_ppm = rem and the call to
rte_log2_u64(abs_ppm)?

> +				if (log_sum > 62) {
> +					shift = log_sum - 62;
> +					/* drop precision */
> +					abs_ppm >>= shift;
> +					divisor >>= shift;
> +				}
> +			}
> +		}
> +
> +		if (divisor)
> +			diff += incval * abs_ppm / divisor;

Does this code risk division by zero? The if (divisor) check protects
against it, but can divisor ever reach zero through the right shift
operations above?

> +		if (negative)
> +			incval -= diff;
> +		else
> +			incval += diff;
> +	}
> +#endif
>  
>  	ret = idpf_ptp_adj_dev_clk_fine(adapter, incval);


More information about the test-report mailing list