All of lore.kernel.org
 help / color / mirror / Atom feed
From: maxime@cerno.tech
To: Karol Herbst <kherbst@redhat.com>, Emma Anholt <emma@anholt.net>,
	Ben Skeggs <bskeggs@redhat.com>, Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: linux-sunxi@lists.linux.dev, Maxime Ripard <maxime@cerno.tech>,
	intel-gfx@lists.freedesktop.org,
	Phil Elwell <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org,
	nouveau@lists.freedesktop.org,
	Hans de Goede <hdegoede@redhat.com>,
	Dom Cobley <dom@raspberrypi.com>,
	Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>,
	dri-devel@lists.freedesktop.org,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	linux-kernel@vger.kernel.org, Noralf Trønnes <noralf@tronnes.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function
Date: Wed, 26 Oct 2022 17:33:27 +0200	[thread overview]
Message-ID: <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>

The current construction of the named mode parsing doesn't allow to extend
it easily. Let's move it to a separate function so we can add more
parameters and modes.

In order for the tests to still pass, some extra checks are needed, so
it's not a 1:1 move.

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

---
Changes in v6:
- Simplify the test for connection status extras
- Simplify the code path to call drm_mode_parse_cmdline_named_mode

Changes in v4:
- Fold down all the named mode patches that were split into a single
  patch again to maintain bisectability
---
 drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 71c050c3ee6b..37542612912b 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_whitelist[] = {
 	"PAL",
 };
 
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+					     unsigned int name_end,
+					     struct drm_cmdline_mode *cmdline_mode)
+{
+	unsigned int i;
+
+	if (!name_end)
+		return 0;
+
+	/* If the name starts with a digit, it's not a named mode */
+	if (isdigit(name[0]))
+		return 0;
+
+	/*
+	 * If there's an equal sign in the name, the command-line
+	 * contains only an option and no mode.
+	 */
+	if (strnchr(name, name_end, '='))
+		return 0;
+
+	/* The connection status extras can be set without a mode. */
+	if (name_end == 1 &&
+	    (name[0] == 'd' || name[0] == 'D' || name[0] == 'e'))
+		return 0;
+
+	/*
+	 * We're sure we're a named mode at this point, iterate over the
+	 * list of modes we're aware of.
+	 */
+	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+		int ret;
+
+		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+		if (ret != name_end)
+			continue;
+
+		strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]);
+		cmdline_mode->specified = true;
+
+		return 1;
+	}
+
+	return -EINVAL;
+}
+
 /**
  * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  * @mode_option: optional per connector mode option
@@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
 	const char *options_ptr = NULL;
 	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
-	int i, len, ret;
+	int len, ret;
 
 	memset(mode, 0, sizeof(*mode));
 	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 		parse_extras = true;
 	}
 
-	/* First check for a named mode */
-	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
-		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
-		if (ret == mode_end) {
-			if (refresh_ptr)
-				return false; /* named + refresh is invalid */
+	if (!mode_end)
+		return false;
 
-			strcpy(mode->name, drm_named_modes_whitelist[i]);
-			mode->specified = true;
-			break;
-		}
-	}
+	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
+	if (ret < 0)
+		return false;
+
+	/*
+	 * Having a mode that starts by a letter (and thus is named) and
+	 * an at-sign (used to specify a refresh rate) is disallowed.
+	 */
+	if (ret && refresh_ptr)
+		return false;
 
 	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
 	if (!mode->specified && isdigit(name[0])) {

-- 
b4 0.11.0-dev-99e3a

WARNING: multiple messages have this Message-ID (diff)
From: maxime@cerno.tech
To: Karol Herbst <kherbst@redhat.com>, Emma Anholt <emma@anholt.net>,
	Ben Skeggs <bskeggs@redhat.com>,  Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	 Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	 Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: Dom Cobley <dom@raspberrypi.com>,
	nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-sunxi@lists.linux.dev, Hans de Goede <hdegoede@redhat.com>,
	Noralf Trønnes <noralf@tronnes.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Maxime Ripard <maxime@cerno.tech>,
	Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>,
	Phil Elwell <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [Nouveau] [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function
Date: Wed, 26 Oct 2022 17:33:27 +0200	[thread overview]
Message-ID: <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>

The current construction of the named mode parsing doesn't allow to extend
it easily. Let's move it to a separate function so we can add more
parameters and modes.

In order for the tests to still pass, some extra checks are needed, so
it's not a 1:1 move.

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

---
Changes in v6:
- Simplify the test for connection status extras
- Simplify the code path to call drm_mode_parse_cmdline_named_mode

Changes in v4:
- Fold down all the named mode patches that were split into a single
  patch again to maintain bisectability
---
 drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 71c050c3ee6b..37542612912b 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_whitelist[] = {
 	"PAL",
 };
 
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+					     unsigned int name_end,
+					     struct drm_cmdline_mode *cmdline_mode)
+{
+	unsigned int i;
+
+	if (!name_end)
+		return 0;
+
+	/* If the name starts with a digit, it's not a named mode */
+	if (isdigit(name[0]))
+		return 0;
+
+	/*
+	 * If there's an equal sign in the name, the command-line
+	 * contains only an option and no mode.
+	 */
+	if (strnchr(name, name_end, '='))
+		return 0;
+
+	/* The connection status extras can be set without a mode. */
+	if (name_end == 1 &&
+	    (name[0] == 'd' || name[0] == 'D' || name[0] == 'e'))
+		return 0;
+
+	/*
+	 * We're sure we're a named mode at this point, iterate over the
+	 * list of modes we're aware of.
+	 */
+	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+		int ret;
+
+		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+		if (ret != name_end)
+			continue;
+
+		strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]);
+		cmdline_mode->specified = true;
+
+		return 1;
+	}
+
+	return -EINVAL;
+}
+
 /**
  * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  * @mode_option: optional per connector mode option
@@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
 	const char *options_ptr = NULL;
 	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
-	int i, len, ret;
+	int len, ret;
 
 	memset(mode, 0, sizeof(*mode));
 	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 		parse_extras = true;
 	}
 
-	/* First check for a named mode */
-	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
-		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
-		if (ret == mode_end) {
-			if (refresh_ptr)
-				return false; /* named + refresh is invalid */
+	if (!mode_end)
+		return false;
 
-			strcpy(mode->name, drm_named_modes_whitelist[i]);
-			mode->specified = true;
-			break;
-		}
-	}
+	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
+	if (ret < 0)
+		return false;
+
+	/*
+	 * Having a mode that starts by a letter (and thus is named) and
+	 * an at-sign (used to specify a refresh rate) is disallowed.
+	 */
+	if (ret && refresh_ptr)
+		return false;
 
 	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
 	if (!mode->specified && isdigit(name[0])) {

-- 
b4 0.11.0-dev-99e3a

WARNING: multiple messages have this Message-ID (diff)
From: maxime@cerno.tech
To: Karol Herbst <kherbst@redhat.com>, Emma Anholt <emma@anholt.net>,
	Ben Skeggs <bskeggs@redhat.com>,  Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	 Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	 Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: Dom Cobley <dom@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-sunxi@lists.linux.dev, Hans de Goede <hdegoede@redhat.com>,
	Noralf Trønnes <noralf@tronnes.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Maxime Ripard <maxime@cerno.tech>,
	Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>,
	Phil Elwell <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function
Date: Wed, 26 Oct 2022 17:33:27 +0200	[thread overview]
Message-ID: <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>

The current construction of the named mode parsing doesn't allow to extend
it easily. Let's move it to a separate function so we can add more
parameters and modes.

In order for the tests to still pass, some extra checks are needed, so
it's not a 1:1 move.

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

---
Changes in v6:
- Simplify the test for connection status extras
- Simplify the code path to call drm_mode_parse_cmdline_named_mode

Changes in v4:
- Fold down all the named mode patches that were split into a single
  patch again to maintain bisectability
---
 drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 71c050c3ee6b..37542612912b 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_whitelist[] = {
 	"PAL",
 };
 
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+					     unsigned int name_end,
+					     struct drm_cmdline_mode *cmdline_mode)
+{
+	unsigned int i;
+
+	if (!name_end)
+		return 0;
+
+	/* If the name starts with a digit, it's not a named mode */
+	if (isdigit(name[0]))
+		return 0;
+
+	/*
+	 * If there's an equal sign in the name, the command-line
+	 * contains only an option and no mode.
+	 */
+	if (strnchr(name, name_end, '='))
+		return 0;
+
+	/* The connection status extras can be set without a mode. */
+	if (name_end == 1 &&
+	    (name[0] == 'd' || name[0] == 'D' || name[0] == 'e'))
+		return 0;
+
+	/*
+	 * We're sure we're a named mode at this point, iterate over the
+	 * list of modes we're aware of.
+	 */
+	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+		int ret;
+
+		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+		if (ret != name_end)
+			continue;
+
+		strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]);
+		cmdline_mode->specified = true;
+
+		return 1;
+	}
+
+	return -EINVAL;
+}
+
 /**
  * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  * @mode_option: optional per connector mode option
@@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
 	const char *options_ptr = NULL;
 	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
-	int i, len, ret;
+	int len, ret;
 
 	memset(mode, 0, sizeof(*mode));
 	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 		parse_extras = true;
 	}
 
-	/* First check for a named mode */
-	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
-		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
-		if (ret == mode_end) {
-			if (refresh_ptr)
-				return false; /* named + refresh is invalid */
+	if (!mode_end)
+		return false;
 
-			strcpy(mode->name, drm_named_modes_whitelist[i]);
-			mode->specified = true;
-			break;
-		}
-	}
+	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
+	if (ret < 0)
+		return false;
+
+	/*
+	 * Having a mode that starts by a letter (and thus is named) and
+	 * an at-sign (used to specify a refresh rate) is disallowed.
+	 */
+	if (ret && refresh_ptr)
+		return false;
 
 	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
 	if (!mode->specified && isdigit(name[0])) {

-- 
b4 0.11.0-dev-99e3a

WARNING: multiple messages have this Message-ID (diff)
From: maxime@cerno.tech
To: Karol Herbst <kherbst@redhat.com>, Emma Anholt <emma@anholt.net>,
	Ben Skeggs <bskeggs@redhat.com>,  Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	 Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	 Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: Dom Cobley <dom@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-sunxi@lists.linux.dev, Hans de Goede <hdegoede@redhat.com>,
	Noralf Trønnes <noralf@tronnes.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Maxime Ripard <maxime@cerno.tech>,
	Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>,
	Phil Elwell <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [Intel-gfx] [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function
Date: Wed, 26 Oct 2022 17:33:27 +0200	[thread overview]
Message-ID: <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>

The current construction of the named mode parsing doesn't allow to extend
it easily. Let's move it to a separate function so we can add more
parameters and modes.

In order for the tests to still pass, some extra checks are needed, so
it's not a 1:1 move.

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

---
Changes in v6:
- Simplify the test for connection status extras
- Simplify the code path to call drm_mode_parse_cmdline_named_mode

Changes in v4:
- Fold down all the named mode patches that were split into a single
  patch again to maintain bisectability
---
 drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 71c050c3ee6b..37542612912b 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_whitelist[] = {
 	"PAL",
 };
 
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+					     unsigned int name_end,
+					     struct drm_cmdline_mode *cmdline_mode)
+{
+	unsigned int i;
+
+	if (!name_end)
+		return 0;
+
+	/* If the name starts with a digit, it's not a named mode */
+	if (isdigit(name[0]))
+		return 0;
+
+	/*
+	 * If there's an equal sign in the name, the command-line
+	 * contains only an option and no mode.
+	 */
+	if (strnchr(name, name_end, '='))
+		return 0;
+
+	/* The connection status extras can be set without a mode. */
+	if (name_end == 1 &&
+	    (name[0] == 'd' || name[0] == 'D' || name[0] == 'e'))
+		return 0;
+
+	/*
+	 * We're sure we're a named mode at this point, iterate over the
+	 * list of modes we're aware of.
+	 */
+	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+		int ret;
+
+		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+		if (ret != name_end)
+			continue;
+
+		strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]);
+		cmdline_mode->specified = true;
+
+		return 1;
+	}
+
+	return -EINVAL;
+}
+
 /**
  * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  * @mode_option: optional per connector mode option
@@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
 	const char *options_ptr = NULL;
 	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
-	int i, len, ret;
+	int len, ret;
 
 	memset(mode, 0, sizeof(*mode));
 	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 		parse_extras = true;
 	}
 
-	/* First check for a named mode */
-	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
-		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
-		if (ret == mode_end) {
-			if (refresh_ptr)
-				return false; /* named + refresh is invalid */
+	if (!mode_end)
+		return false;
 
-			strcpy(mode->name, drm_named_modes_whitelist[i]);
-			mode->specified = true;
-			break;
-		}
-	}
+	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
+	if (ret < 0)
+		return false;
+
+	/*
+	 * Having a mode that starts by a letter (and thus is named) and
+	 * an at-sign (used to specify a refresh rate) is disallowed.
+	 */
+	if (ret && refresh_ptr)
+		return false;
 
 	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
 	if (!mode->specified && isdigit(name[0])) {

-- 
b4 0.11.0-dev-99e3a

WARNING: multiple messages have this Message-ID (diff)
From: maxime@cerno.tech
To: Karol Herbst <kherbst@redhat.com>, Emma Anholt <emma@anholt.net>,
	Ben Skeggs <bskeggs@redhat.com>, Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: linux-sunxi@lists.linux.dev, Maxime Ripard <maxime@cerno.tech>,
	intel-gfx@lists.freedesktop.org,
	Phil Elwell <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org,
	nouveau@lists.freedesktop.org,
	Hans de Goede <hdegoede@redhat.com>,
	Dom Cobley <dom@raspberrypi.com>,
	Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>,
	dri-devel@lists.freedesktop.org,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	linux-kernel@vger.kernel.org, Noralf Trønnes <noralf@tronnes.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function
Date: Wed, 26 Oct 2022 17:33:27 +0200	[thread overview]
Message-ID: <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>

The current construction of the named mode parsing doesn't allow to extend
it easily. Let's move it to a separate function so we can add more
parameters and modes.

In order for the tests to still pass, some extra checks are needed, so
it's not a 1:1 move.

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

---
Changes in v6:
- Simplify the test for connection status extras
- Simplify the code path to call drm_mode_parse_cmdline_named_mode

Changes in v4:
- Fold down all the named mode patches that were split into a single
  patch again to maintain bisectability
---
 drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 71c050c3ee6b..37542612912b 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_whitelist[] = {
 	"PAL",
 };
 
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+					     unsigned int name_end,
+					     struct drm_cmdline_mode *cmdline_mode)
+{
+	unsigned int i;
+
+	if (!name_end)
+		return 0;
+
+	/* If the name starts with a digit, it's not a named mode */
+	if (isdigit(name[0]))
+		return 0;
+
+	/*
+	 * If there's an equal sign in the name, the command-line
+	 * contains only an option and no mode.
+	 */
+	if (strnchr(name, name_end, '='))
+		return 0;
+
+	/* The connection status extras can be set without a mode. */
+	if (name_end == 1 &&
+	    (name[0] == 'd' || name[0] == 'D' || name[0] == 'e'))
+		return 0;
+
+	/*
+	 * We're sure we're a named mode at this point, iterate over the
+	 * list of modes we're aware of.
+	 */
+	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+		int ret;
+
+		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+		if (ret != name_end)
+			continue;
+
+		strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]);
+		cmdline_mode->specified = true;
+
+		return 1;
+	}
+
+	return -EINVAL;
+}
+
 /**
  * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  * @mode_option: optional per connector mode option
@@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
 	const char *options_ptr = NULL;
 	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
-	int i, len, ret;
+	int len, ret;
 
 	memset(mode, 0, sizeof(*mode));
 	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 		parse_extras = true;
 	}
 
-	/* First check for a named mode */
-	for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
-		ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
-		if (ret == mode_end) {
-			if (refresh_ptr)
-				return false; /* named + refresh is invalid */
+	if (!mode_end)
+		return false;
 
-			strcpy(mode->name, drm_named_modes_whitelist[i]);
-			mode->specified = true;
-			break;
-		}
-	}
+	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
+	if (ret < 0)
+		return false;
+
+	/*
+	 * Having a mode that starts by a letter (and thus is named) and
+	 * an at-sign (used to specify a refresh rate) is disallowed.
+	 */
+	if (ret && refresh_ptr)
+		return false;
 
 	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
 	if (!mode->specified && isdigit(name[0])) {

-- 
b4 0.11.0-dev-99e3a

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-10-26 15:33 UTC|newest]

Thread overview: 222+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 15:33 [PATCH v6 00/23] drm: Analog TV Improvements maxime
2022-10-26 15:33 ` maxime
2022-10-26 15:33 ` [Intel-gfx] " maxime
2022-10-26 15:33 ` maxime
2022-10-26 15:33 ` [Nouveau] " maxime
2022-10-26 15:33 ` [Intel-gfx] [PATCH v6 01/23] drm/tests: Add Kunit Helpers maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33 ` [PATCH v6 02/23] drm/connector: Rename legacy TV property maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 03/23] drm/connector: Only register TV mode property if present maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 04/23] drm/connector: Rename drm_mode_create_tv_properties maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 05/23] drm/connector: Add TV standard property maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 06/23] drm/modes: Add a function to generate analog display modes maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 07/23] drm/client: Add some tests for drm_connector_pick_cmdline_mode() maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` maxime [this message]
2022-10-26 15:33   ` [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-11-05 14:02   ` Noralf Trønnes
2022-11-05 14:02     ` [Intel-gfx] " Noralf Trønnes
2022-11-05 14:02     ` Noralf Trønnes
2022-11-05 14:02     ` Noralf Trønnes
2022-11-05 14:02     ` [Nouveau] " Noralf Trønnes
2022-10-26 15:33 ` [PATCH v6 09/23] drm/modes: Switch to named mode descriptors maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-11-05 14:06   ` Noralf Trønnes
2022-11-05 14:06     ` Noralf Trønnes
2022-11-05 14:06     ` [Intel-gfx] " Noralf Trønnes
2022-11-05 14:06     ` Noralf Trønnes
2022-11-05 14:06     ` [Nouveau] " Noralf Trønnes
2022-10-26 15:33 ` [PATCH v6 10/23] drm/modes: Fill drm_cmdline mode from named modes maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-11-06 13:04   ` Noralf Trønnes
2022-11-06 13:04     ` Noralf Trønnes
2022-11-06 13:04     ` [Intel-gfx] " Noralf Trønnes
2022-11-06 13:04     ` Noralf Trønnes
2022-11-06 13:04     ` [Nouveau] " Noralf Trønnes
2022-11-07 10:02     ` Maxime Ripard
2022-11-07 10:02       ` Maxime Ripard
2022-11-07 10:02       ` [Intel-gfx] " Maxime Ripard
2022-11-07 10:02       ` Maxime Ripard
2022-11-07 10:02       ` [Nouveau] " Maxime Ripard
2022-10-26 15:33 ` [PATCH v6 11/23] drm/connector: Add pixel clock to cmdline mode maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-11-06 13:06   ` Noralf Trønnes
2022-11-06 13:06     ` [Intel-gfx] " Noralf Trønnes
2022-11-06 13:06     ` Noralf Trønnes
2022-11-06 13:06     ` Noralf Trønnes
2022-11-06 13:06     ` [Nouveau] " Noralf Trønnes
2022-10-26 15:33 ` [PATCH v6 12/23] drm/connector: Add a function to lookup a TV mode by its name maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 13/23] drm/modes: Introduce the tv_mode property as a command-line option maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-11-06 13:10   ` Noralf Trønnes
2022-11-06 13:10     ` Noralf Trønnes
2022-11-06 13:10     ` [Intel-gfx] " Noralf Trønnes
2022-11-06 13:10     ` Noralf Trønnes
2022-11-06 13:10     ` [Nouveau] " Noralf Trønnes
2022-11-06 15:51     ` Lukas Satin
2022-10-26 15:33 ` [PATCH v6 14/23] drm/modes: Properly generate a drm_display_mode from a named mode maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 21:25   ` Mateusz Kwiatkowski
2022-10-26 21:25     ` Mateusz Kwiatkowski
2022-10-26 21:25     ` [Intel-gfx] " Mateusz Kwiatkowski
2022-10-26 21:25     ` Mateusz Kwiatkowski
2022-10-26 21:25     ` [Nouveau] " Mateusz Kwiatkowski
2022-11-05 17:50   ` Noralf Trønnes
2022-11-05 17:50     ` Noralf Trønnes
2022-11-05 17:50     ` [Intel-gfx] " Noralf Trønnes
2022-11-05 17:50     ` Noralf Trønnes
2022-11-05 17:50     ` [Nouveau] " Noralf Trønnes
2022-11-07 13:34     ` Maxime Ripard
2022-11-07 13:34       ` Maxime Ripard
2022-11-07 13:34       ` [Intel-gfx] " Maxime Ripard
2022-11-07 13:34       ` Maxime Ripard
2022-11-07 13:34       ` [Nouveau] " Maxime Ripard
2022-10-26 15:33 ` [PATCH v6 15/23] drm/modes: Introduce more named modes maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 22:02   ` Mateusz Kwiatkowski
2022-10-26 22:02     ` Mateusz Kwiatkowski
2022-10-26 22:02     ` [Intel-gfx] " Mateusz Kwiatkowski
2022-10-26 22:02     ` Mateusz Kwiatkowski
2022-10-26 22:02     ` [Nouveau] " Mateusz Kwiatkowski
2022-10-27  9:37     ` Maxime Ripard
2022-10-27  9:37       ` Maxime Ripard
2022-10-27  9:37       ` [Intel-gfx] " Maxime Ripard
2022-10-27  9:37       ` Maxime Ripard
2022-10-27  9:37       ` [Nouveau] " Maxime Ripard
2022-11-06 16:59     ` Noralf Trønnes
2022-11-06 16:59       ` Noralf Trønnes
2022-11-06 16:59       ` [Intel-gfx] " Noralf Trønnes
2022-11-06 16:59       ` Noralf Trønnes
2022-11-06 16:59       ` [Nouveau] " Noralf Trønnes
2022-11-07 10:07       ` Maxime Ripard
2022-11-07 10:07         ` Maxime Ripard
2022-11-07 10:07         ` [Intel-gfx] " Maxime Ripard
2022-11-07 10:07         ` Maxime Ripard
2022-11-07 10:07         ` [Nouveau] " Maxime Ripard
2022-11-07 11:17         ` Noralf Trønnes
2022-11-07 11:17           ` Noralf Trønnes
2022-11-07 11:17           ` [Intel-gfx] " Noralf Trønnes
2022-11-07 11:17           ` Noralf Trønnes
2022-11-07 11:17           ` [Nouveau] " Noralf Trønnes
2022-11-06 16:33   ` Noralf Trønnes
2022-11-06 16:33     ` Noralf Trønnes
2022-11-06 16:33     ` [Intel-gfx] " Noralf Trønnes
2022-11-06 16:33     ` Noralf Trønnes
2022-11-06 16:33     ` [Nouveau] " Noralf Trønnes
2022-11-07 10:21     ` Maxime Ripard
2022-11-07 10:21       ` Maxime Ripard
2022-11-07 10:21       ` [Intel-gfx] " Maxime Ripard
2022-11-07 10:21       ` Maxime Ripard
2022-11-07 10:21       ` [Nouveau] " Maxime Ripard
2022-11-07 11:29       ` Noralf Trønnes
2022-11-07 11:29         ` Noralf Trønnes
2022-11-07 11:29         ` [Intel-gfx] " Noralf Trønnes
2022-11-07 11:29         ` Noralf Trønnes
2022-11-07 11:29         ` [Nouveau] " Noralf Trønnes
2022-11-07 12:45         ` Maxime Ripard
2022-11-07 12:45           ` Maxime Ripard
2022-11-07 12:45           ` [Intel-gfx] " Maxime Ripard
2022-11-07 12:45           ` Maxime Ripard
2022-11-07 12:45           ` [Nouveau] " Maxime Ripard
2022-10-26 15:33 ` [PATCH v6 17/23] drm/atomic-helper: Add a TV properties reset helper maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 18/23] drm/atomic-helper: Add an analog TV atomic_check implementation maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33 ` [PATCH v6 19/23] drm/vc4: vec: Use TV Reset implementation maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33 ` [PATCH v6 20/23] drm/vc4: vec: Check for VEC output constraints maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 21/23] drm/vc4: vec: Convert to the new TV mode property maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 15:33 ` [PATCH v6 22/23] drm/vc4: vec: Add support for more analog TV standards maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 22:32   ` Mateusz Kwiatkowski
2022-10-26 22:32     ` Mateusz Kwiatkowski
2022-10-26 22:32     ` [Intel-gfx] " Mateusz Kwiatkowski
2022-10-26 22:32     ` Mateusz Kwiatkowski
2022-10-26 22:32     ` [Nouveau] " Mateusz Kwiatkowski
2022-10-27 11:58     ` Maxime Ripard
2022-10-27 11:58       ` [Intel-gfx] " Maxime Ripard
2022-10-27 11:58       ` Maxime Ripard
2022-10-27 11:58       ` Maxime Ripard
2022-10-27 11:58       ` [Nouveau] " Maxime Ripard
2022-10-26 15:33 ` [PATCH v6 23/23] drm/sun4i: tv: Convert to the new TV mode property maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Intel-gfx] " maxime
2022-10-26 15:33   ` maxime
2022-10-26 15:33   ` [Nouveau] " maxime
2022-10-26 17:01 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for drm: Analog TV Improvements (rev6) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech \
    --to=maxime@cerno.tech \
    --cc=airlied@linux.ie \
    --cc=bskeggs@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dom@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emma@anholt.net \
    --cc=geert@linux-m68k.org \
    --cc=hdegoede@redhat.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kfyatek+publicgit@gmail.com \
    --cc=kherbst@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=phil@raspberrypi.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=samuel@sholland.org \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=tzimmermann@suse.de \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.