[05/12] drm/modes: parse_cmdline: Rework drm_mode_parse_cmdline_options()

Submitted by Hans de Goede on Nov. 10, 2019, 3:40 p.m.

Details

Message ID 20191110154101.26486-6-hdegoede@redhat.com
State New
Headers show
Series "drm/modes: parse_cmdline: Add support for specifying panel_orientation on the kernel cmdline" ( rev: 1 ) in DRI devel

Not browsing as part of any series.

Commit Message

Hans de Goede Nov. 10, 2019, 3:40 p.m.
Refactor drm_mode_parse_cmdline_options() so that it takes a pointer
to the first option, rather then a pointer to the ',' before the first
option.

This is a preparation patch for allowing parsing of stand-alone options
without a mode before them, e.g.: video=HDMI-1:margin_right=14,...

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/drm_modes.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index f49401124727..25e8edf4cfb8 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1591,23 +1591,21 @@  static int drm_mode_parse_cmdline_int(const char *delim, unsigned int *int_ret)
 	return 0;
 }
 
-static int drm_mode_parse_cmdline_options(const char *str, size_t len,
+static int drm_mode_parse_cmdline_options(const char *str,
 					  const struct drm_connector *connector,
 					  struct drm_cmdline_mode *mode)
 {
 	unsigned int deg, margin, rotation = 0;
-	const char *sep = str;
+	const char *delim, *option, *sep;
 
-	while ((sep = strchr(sep, ','))) {
-		const char *delim, *option;
-
-		option = sep + 1;
+	option = str;
+	do {
 		delim = strchr(option, '=');
 		if (!delim) {
 			delim = strchr(option, ',');
 
 			if (!delim)
-				delim = str + len;
+				delim = option + strlen(option);
 		}
 
 		if (!strncmp(option, "rotate", delim - option)) {
@@ -1661,8 +1659,9 @@  static int drm_mode_parse_cmdline_options(const char *str, size_t len,
 		} else {
 			return -EINVAL;
 		}
-		sep = delim;
-	}
+		sep = strchr(delim, ',');
+		option = sep + 1;
+	} while (sep);
 
 	mode->rotation_reflection = rotation;
 
@@ -1855,9 +1854,7 @@  bool drm_mode_parse_command_line_for_connector(const char *mode_option,
 	}
 
 	if (options_ptr) {
-		int len = strlen(name) - (options_ptr - name);
-
-		ret = drm_mode_parse_cmdline_options(options_ptr, len,
+		ret = drm_mode_parse_cmdline_options(options_ptr + 1,
 						     connector, mode);
 		if (ret)
 			return false;