On Fri, Mar 20, 2026 at 06:05:44AM +0100, Aleksandr Loktionov wrote: > From: Lukasz Czapnik <[email protected]> > > In ice_sched_bw_to_rl_profile(), the loop over 64 bits computes the > scheduler timestamp rate as: > > ts_rate = div64_long((s64)hw->psm_clk_freq, > pow_result * ICE_RL_PROF_TS_MULTIPLIER); > > where pow_result = BIT_ULL(i). For large values of i, the product > pow_result * ICE_RL_PROF_TS_MULTIPLIER overflows u64 before being used > as the divisor, producing incorrect ts_rate values and potentially > undefined behaviour. > > Fix this by pre-computing ts_freq = hw->psm_clk_freq / > ICE_RL_PROF_TS_MULTIPLIER once before the loop and then dividing only > by pow_result inside the loop. The division order avoids the overflow > while preserving the same mathematical result. Declare ts_freq as s64 > to match the type domain of the surrounding arithmetic and avoid a > redundant cast at the use site. > > While at it, scope the loop variable i to the for statement itself. > > Fixes: 1ddef455f4a8 ("ice: Add NDO callback to set the maximum per-queue > bitrate") > Signed-off-by: Lukasz Czapnik <[email protected]> > Signed-off-by: Aleksandr Loktionov <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
