Skip to contentSkip to conversation

tests/kms_setmode: Fix clone mode mismatch by preferring eDP mode

PATCH New Jeevan B 1 participant 3 messages Sep 22, 2025

lore
Share & tools
lore

Jeevan B

author
#0 lore raw

cover tests/kms_setmode: Fix clone mode mismatch by preferring eDP mode

If an eDP connector is present, prefer selecting its default mode for cloning. Some eDP panels support only high refresh rate (HRR) modes, which may not be compatible with external displays. To avoid invalid clone configurations and test failures, we choose the default mode from the eDP connector when available.

Jeevan B (2):
tests/kms_setmode: simplify mode selection by removing goto tests/kms_setmode: Fix clone mode mismatch by preferring eDP mode

 tests/kms_setmode.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 tests/kms_setmode: simplify mode selection by removing goto

Replaced 'goto found' with early returns in get_mode_for_crtc() and added braces around the fallback loop. This makes the logic cleaner and easier to follow without changing behavior.

v2: write to *mode_ret before returning from function.

---
 tests/kms_setmode.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
tests/kms_setmode.c +11 -6
index 484c3a95f..48d0c3e1e 100644
@@ -238,8 +238,10 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 	 */
 	for (i = 0; i < crtc->connector_count; i++) {
 		mode = &crtc->cconfs[i].default_mode;
-		if (crtc_supports_mode(crtc, mode))
-			goto found;
+		if (crtc_supports_mode(crtc, mode)) {
+			*mode_ret = *mode;
+			return;
+		}
 	}
 
 	/*
@@ -248,8 +250,10 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 	 */
 	for (i = 0; i < crtc->cconfs[0].connector->count_modes; i++) {
 		mode = &crtc->cconfs[0].connector->modes[i];
-		if (crtc_supports_mode(crtc, mode))
-			goto found;
+		if (crtc_supports_mode(crtc, mode)) {
+			*mode_ret = *mode;
+			return;
+		}
 	}
 
 	/*
@@ -258,10 +262,11 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 	 * scaling etc.
 	 */
 	mode = &crtc->cconfs[0].default_mode;
-	for (i = 1; i < crtc->connector_count; i++)
+	for (i = 1; i < crtc->connector_count; i++) {
 		if (crtc->cconfs[i].default_mode.clock < mode->clock)
 			mode = &crtc->cconfs[i].default_mode;
-found:
+	}
+
 	*mode_ret = *mode;
 }
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 tests/kms_setmode: Fix clone mode mismatch by preferring eDP mode

In reply to Jeevan B

If an eDP connector is present, prefer selecting its lowest clock mode for cloning. Some eDP panels support only high refresh rate (HRR) modes, which may not match modes supported by external displays. To avoid invalid clone configurations and test failures, we choose the lowest clock mode from the eDP connector when available.

v2: Fix logic for eDP fallback.
v3: Fix comment to say ‘lowest clock mode selected’ instead of
‘default mode’.
v4: Update commit message.

---
 tests/kms_setmode.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
tests/kms_setmode.c +19 -0
index 48d0c3e1e..135918007 100644
@@ -256,6 +256,25 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 		}
 	}
 
+	/* If an eDP connector is present, iterate through its modes and
+	 * pick a mode with lowest clock, since internal panels typically
+	 * dictate the clone mode and may have HRR support, making them
+	 * incompatible with modes supported by external displays.
+	 */
+	for (i = 0; i < crtc->connector_count; i++) {
+		drmModeConnector *conn = crtc->cconfs[i].connector;
+
+		if (conn->connector_type == DRM_MODE_CONNECTOR_eDP) {
+			mode = &conn->modes[0];
+			for (int j = 1; j < conn->count_modes; j++) {
+				if (conn->modes[j].clock < mode->clock)
+					mode = &conn->modes[j];
+			}
+			*mode_ret = *mode;
+			return;
+		}
+	}
+
 	/*
 	 * If none is found then just pick the default mode from all connectors
 	 * with the smallest clock, hope the other connectors can support it by
Signature · 1 line
2.43.0