diff mbox series

[v2,18/33] drm/modes: Bail out of named mode parsing early if it's a status

Message ID 20220728-rpi-analog-tv-properties-v2-18-f733a0ed9f90@cerno.tech (mailing list archive)
State New, archived
Headers show
Series drm: Analog TV Improvements | expand

Commit Message

Maxime Ripard Sept. 22, 2022, 2:25 p.m. UTC
The name we are given is the first part of the command line, the part
before any option.

The most trivial case is thus that we're parsing a mode. However, the
connection status uses a single character to encode what status we want
to force on a connector.

It's thus fairly easy to confuse that character with a named mode, and
our current code works because the list of the named modes we consider
doesn't start with any of those characters.

However, it's not very obvious and quite fragile, so let's add an
explicit test for this, with some comment to explain what's going on.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index dc5d5bdbea7a..9cee0ad806b8 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2249,6 +2249,15 @@  static int drm_mode_parse_cmdline_named_mode(const char *name,
 	if (strnchr(name, name_end, '='))
 		return 0;
 
+#define STR_STRICT_EQ(str, len, cmp) \
+	(str_has_prefix(str, cmp) == len)
+
+	/* The connection status extras can be set without a mode. */
+	if (STR_STRICT_EQ(name, name_end, "d") ||
+	    STR_STRICT_EQ(name, name_end, "D") ||
+	    STR_STRICT_EQ(name, name_end, "e"))
+		return 0;
+
 	/*
 	 * We're sure we're a named mode at that point, iterate over the
 	 * list of modes we're aware of.