1 From 0e7c5e80d8d310a881d723a426762e8822d5bf35 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Mon, 18 Nov 2019 16:51:24 +0100
4 Subject: [PATCH] drm/modes: parse_cmdline: Stop parsing extras after
7 Commit c2ed3e941901810ad3d55ce1935fa22c5007fee4 upstream.
9 Before this commit it was impossible to add an extra mode argument after
10 a bpp or refresh specifier, combined with an option, e.g.
11 video=HDMI-1:720x480-24e,rotate=180 would not work, either the "e" to
12 force enable would need to be dropped or the ",rotate=180", otherwise
13 the mode_option would not be accepted.
15 This commit fixes this by fixing the length calculation if extras_ptr
16 is set to stop the extra parsing at the start of the options (stop at the
17 ',' options_ptr points to).
19 Acked-by: Maxime Ripard <mripard@kernel.org>
20 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
21 Link: https://patchwork.freedesktop.org/patch/msgid/20191118155134.30468-3-hdegoede@redhat.com
23 drivers/gpu/drm/drm_modes.c | 10 ++++---
24 .../gpu/drm/selftests/drm_cmdline_selftests.h | 1 +
25 .../drm/selftests/test-drm_cmdline_parser.c | 26 +++++++++++++++++++
26 3 files changed, 33 insertions(+), 4 deletions(-)
28 --- a/drivers/gpu/drm/drm_modes.c
29 +++ b/drivers/gpu/drm/drm_modes.c
30 @@ -1721,7 +1721,7 @@ bool drm_mode_parse_command_line_for_con
31 const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
32 const char *options_ptr = NULL;
33 char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
39 @@ -1841,9 +1841,11 @@ bool drm_mode_parse_command_line_for_con
41 extra_ptr = refresh_end_ptr;
44 - extra_ptr != options_ptr) {
45 - int len = strlen(name) - (extra_ptr - name);
48 + len = options_ptr - extra_ptr;
50 + len = strlen(extra_ptr);
52 ret = drm_mode_parse_cmdline_extra(extra_ptr, len, false,
54 --- a/drivers/gpu/drm/selftests/drm_cmdline_selftests.h
55 +++ b/drivers/gpu/drm/selftests/drm_cmdline_selftests.h
56 @@ -60,3 +60,4 @@ cmdline_test(drm_cmdline_test_vmirror)
57 cmdline_test(drm_cmdline_test_margin_options)
58 cmdline_test(drm_cmdline_test_multiple_options)
59 cmdline_test(drm_cmdline_test_invalid_option)
60 +cmdline_test(drm_cmdline_test_bpp_extra_and_option)
61 --- a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
62 +++ b/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
63 @@ -992,6 +992,32 @@ static int drm_cmdline_test_invalid_opti
67 +static int drm_cmdline_test_bpp_extra_and_option(void *ignored)
69 + struct drm_cmdline_mode mode = { };
71 + FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24e,rotate=180",
74 + FAIL_ON(!mode.specified);
75 + FAIL_ON(mode.xres != 720);
76 + FAIL_ON(mode.yres != 480);
77 + FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
79 + FAIL_ON(mode.refresh_specified);
81 + FAIL_ON(!mode.bpp_specified);
82 + FAIL_ON(mode.bpp != 24);
86 + FAIL_ON(mode.interlace);
87 + FAIL_ON(mode.margins);
88 + FAIL_ON(mode.force != DRM_FORCE_ON);
93 #include "drm_selftest.c"
95 static int __init test_drm_cmdline_init(void)