* [PATCH 1/2] drm/i915/snps_hdmi_pll: Fix 64-bit divisor truncation by using div64_u64
2025-06-18 13:09 [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Ankit Nautiyal
@ 2025-06-18 13:09 ` Ankit Nautiyal
2025-06-18 13:09 ` [PATCH 2/2] drm/i915/snps_hdmi_pll: Use clamp() instead of max(min()) Ankit Nautiyal
2025-06-18 19:51 ` [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Jani Nikula
2 siblings, 0 replies; 6+ messages in thread
From: Ankit Nautiyal @ 2025-06-18 13:09 UTC (permalink / raw)
To: intel-gfx
Cc: intel-xe, suraj.kandpal, jani.nikula, stable, Ankit Nautiyal,
Vas Novikov, Jani Nikula
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.novikov@gmail.com>
Closes: https://lore.kernel.org/all/8d7c7958-9558-4c8a-a81a-e9310f2d8852@gmail.com/
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Cc: Suraj Kandpal <suraj.kandpal@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Vas Novikov <vasya.novikov@gmail.com>
Cc: <stable@vger.kernel.org> # v6.15+
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@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
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] drm/i915/snps_hdmi_pll: Use clamp() instead of max(min())
2025-06-18 13:09 [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Ankit Nautiyal
2025-06-18 13:09 ` [PATCH 1/2] drm/i915/snps_hdmi_pll: Fix 64-bit divisor truncation by using div64_u64 Ankit Nautiyal
@ 2025-06-18 13:09 ` Ankit Nautiyal
2025-06-18 13:21 ` kernel test robot
2025-06-18 19:51 ` [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Jani Nikula
2 siblings, 1 reply; 6+ messages in thread
From: Ankit Nautiyal @ 2025-06-18 13:09 UTC (permalink / raw)
To: intel-gfx; +Cc: intel-xe, suraj.kandpal, jani.nikula, stable, Ankit Nautiyal
The values of ana_cp_int, and ana_cp_prop are clamped between 1 and 127.
Use the more intuitive and readable clamp() macro instead of using
nested max(min(...)).
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@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 5111bdc3075b..7fe6b4a18213 100644
--- a/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c
+++ b/drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c
@@ -106,7 +106,7 @@ static void get_ana_cp_int_prop(u64 vco_clk,
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));
+ *ana_cp_int = clamp(ana_cp_int_temp, 1, 127);
curve_2_scaled_int = curve_2_scaled1 * (*ana_cp_int);
@@ -125,7 +125,7 @@ static void get_ana_cp_int_prop(u64 vco_clk,
curve_1_interpolated);
*ana_cp_prop = DIV64_U64_ROUND_UP(adjusted_vco_clk2, curve_2_scaled2);
- *ana_cp_prop = max(1, min(*ana_cp_prop, 127));
+ *ana_cp_prop = clamp(*ana_cp_prop, 1, 127);
}
static void compute_hdmi_tmds_pll(u64 pixel_clock, u32 refclk,
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm
2025-06-18 13:09 [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Ankit Nautiyal
2025-06-18 13:09 ` [PATCH 1/2] drm/i915/snps_hdmi_pll: Fix 64-bit divisor truncation by using div64_u64 Ankit Nautiyal
2025-06-18 13:09 ` [PATCH 2/2] drm/i915/snps_hdmi_pll: Use clamp() instead of max(min()) Ankit Nautiyal
@ 2025-06-18 19:51 ` Jani Nikula
2025-06-19 11:56 ` Nautiyal, Ankit K
2 siblings, 1 reply; 6+ messages in thread
From: Jani Nikula @ 2025-06-18 19:51 UTC (permalink / raw)
To: Ankit Nautiyal, intel-gfx; +Cc: intel-xe, suraj.kandpal, stable, Ankit Nautiyal
On Wed, 18 Jun 2025, Ankit Nautiyal <ankit.k.nautiyal@intel.com> wrote:
> Fixes/improvement in snps-phy HDMI PLL algorithm.
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
> Ankit Nautiyal (2):
> drm/i915/snps_hdmi_pll: Fix 64-bit divisor truncation by using
> div64_u64
> drm/i915/snps_hdmi_pll: Use clamp() instead of max(min())
>
> drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm
2025-06-18 19:51 ` [PATCH 0/2] Fixes in snps-phy HDMI PLL algorithm Jani Nikula
@ 2025-06-19 11:56 ` Nautiyal, Ankit K
0 siblings, 0 replies; 6+ messages in thread
From: Nautiyal, Ankit K @ 2025-06-19 11:56 UTC (permalink / raw)
To: Jani Nikula, intel-gfx; +Cc: intel-xe, suraj.kandpal, stable
On 6/19/2025 1:21 AM, Jani Nikula wrote:
> On Wed, 18 Jun 2025, Ankit Nautiyal <ankit.k.nautiyal@intel.com> wrote:
>> Fixes/improvement in snps-phy HDMI PLL algorithm.
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Thank you once again, Jani, for pointing out the sparse warning and for
your reviews.
The series has been pushed to drm-intel-next.
Regards,
Ankit
>
>> Ankit Nautiyal (2):
>> drm/i915/snps_hdmi_pll: Fix 64-bit divisor truncation by using
>> div64_u64
>> drm/i915/snps_hdmi_pll: Use clamp() instead of max(min())
>>
>> drivers/gpu/drm/i915/display/intel_snps_hdmi_pll.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread