Skip to contentSkip to conversation

drm/amd/display: Fix 64 bit wraparound resulting in illegal drm mode

PATCH New Leslie Shi 1 participant 1 message Jun 17, 2022

Subsystems (3)
lore
Share & tools
lore

Leslie Shi

author
#0 lore raw

PATCH 1/1 drm/amd/display: Fix 64 bit wraparound resulting in illegal drm mode

[Why]
For m = drm_display_mode{.clock = 533250, .htotal = 4000, .vtotal = 2222}, common_rates[i] = 60000, the result of target_vtotal is 2221. This cause wraparound of variable target_vtotal_diff.

[How]
Skip the loop if target_vtotal less than m->vtotal

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -0
index c2bc7db85d7e..ed7ab089b224 100644
@@ -8537,6 +8537,10 @@ static uint add_fs_modes(struct amdgpu_dm_connector *aconnector)
 		num = (unsigned long long)m->clock * 1000 * 1000;
 		den = common_rates[i] * (unsigned long long)m->htotal;
 		target_vtotal = div_u64(num, den);
+
+		if (target_vtotal < m->vtotal)
+			continue;
+
 		target_vtotal_diff = target_vtotal - m->vtotal;
 
 		/* Check for illegal modes */
Signature · 1 line
2.25.1