DIV_ROUND_CLOSEST_ULL uses do_div(), which expects a 32-bit divisor.
When passing a 64-bit constant like CURVE2_MULTIPLIER, the value is
silently truncated to u32, potentially leading to incorrect results
on large divisors.

Replace DIV_ROUND_CLOSEST_ULL with DIV64_U64_ROUND_CLOSEST which correctly
handles full 64-bit division.

v2: Use DIV64_U64_ROUND_CLOSEST instead of div64_u64 macro. (Jani)

Fixes: 5947642004bf ("drm/i915/display: Add support for SNPS PHY HDMI PLL 
algorithm for DG2")
Reported-by: Vas Novikov <vasya.novi...@gmail.com>
Closes: 
https://lore.kernel.org/all/8d7c7958-9558-4c8a-a81a-e9310f2d8...@gmail.com/
Cc: Ankit Nautiyal <ankit.k.nauti...@intel.com>
Cc: Suraj Kandpal <suraj.kand...@intel.com>
Cc: Jani Nikula <jani.nik...@intel.com>
Cc: Vas Novikov <vasya.novi...@gmail.com>
Cc: <sta...@vger.kernel.org> # v6.15+
Signed-off-by: Ankit Nautiyal <ankit.k.nauti...@intel.com>
---
 drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c 
b/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c
index 74bb3bedf30f..5111bdc3075b 100644
--- a/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c
+++ b/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c
@@ -103,8 +103,8 @@ static void get_ana_cp_int_prop(u64 vco_clk,
                            DIV_ROUND_DOWN_ULL(curve_1_interpolated, 
CURVE0_MULTIPLIER)));
 
        ana_cp_int_temp =
-               DIV_ROUND_CLOSEST_ULL(DIV_ROUND_DOWN_ULL(adjusted_vco_clk1, 
curve_2_scaled1),
-                                     CURVE2_MULTIPLIER);
+               DIV64_U64_ROUND_CLOSEST(DIV_ROUND_DOWN_ULL(adjusted_vco_clk1, 
curve_2_scaled1),
+                                       CURVE2_MULTIPLIER);
 
        *ana_cp_int = max(1, min(ana_cp_int_temp, 127));
 
-- 
2.45.2

Reply via email to