blob: 1d356eb6abcc506ebf91611c4c5f1417d19c8c88 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 0e7c5e80d8d310a881d723a426762e8822d5bf35 Mon Sep 17 00:00:00 2001
2From: Hans de Goede <hdegoede@redhat.com>
3Date: Mon, 18 Nov 2019 16:51:24 +0100
4Subject: [PATCH] drm/modes: parse_cmdline: Stop parsing extras after
5 bpp / refresh at ', '
6
7Commit c2ed3e941901810ad3d55ce1935fa22c5007fee4 upstream.
8
9Before this commit it was impossible to add an extra mode argument after
10a bpp or refresh specifier, combined with an option, e.g.
11video=HDMI-1:720x480-24e,rotate=180 would not work, either the "e" to
12force enable would need to be dropped or the ",rotate=180", otherwise
13the mode_option would not be accepted.
14
15This commit fixes this by fixing the length calculation if extras_ptr
16is set to stop the extra parsing at the start of the options (stop at the
17',' options_ptr points to).
18
19Acked-by: Maxime Ripard <mripard@kernel.org>
20Signed-off-by: Hans de Goede <hdegoede@redhat.com>
21Link: https://patchwork.freedesktop.org/patch/msgid/20191118155134.30468-3-hdegoede@redhat.com
22---
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(-)
27
28--- a/drivers/gpu/drm/drm_modes.c
29+++ b/drivers/gpu/drm/drm_modes.c
30@@ -1728,7 +1728,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;
34- int ret;
35+ int i, len, ret;
36
37 #ifdef CONFIG_FB
38 if (!mode_option)
39@@ -1848,9 +1848,11 @@ bool drm_mode_parse_command_line_for_con
40 else if (refresh_ptr)
41 extra_ptr = refresh_end_ptr;
42
43- if (extra_ptr &&
44- extra_ptr != options_ptr) {
45- int len = strlen(name) - (extra_ptr - name);
46+ if (extra_ptr) {
47+ if (options_ptr)
48+ len = options_ptr - extra_ptr;
49+ else
50+ len = strlen(extra_ptr);
51
52 ret = drm_mode_parse_cmdline_extra(extra_ptr, len, false,
53 connector, mode);
54--- a/drivers/gpu/drm/selftests/drm_cmdline_selftests.h
55+++ b/drivers/gpu/drm/selftests/drm_cmdline_selftests.h
56@@ -61,3 +61,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@@ -1003,6 +1003,32 @@ static int drm_cmdline_test_invalid_opti
64 return 0;
65 }
66
67+static int drm_cmdline_test_bpp_extra_and_option(void *ignored)
68+{
69+ struct drm_cmdline_mode mode = { };
70+
71+ FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24e,rotate=180",
72+ &no_connector,
73+ &mode));
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);
78+
79+ FAIL_ON(mode.refresh_specified);
80+
81+ FAIL_ON(!mode.bpp_specified);
82+ FAIL_ON(mode.bpp != 24);
83+
84+ FAIL_ON(mode.rb);
85+ FAIL_ON(mode.cvt);
86+ FAIL_ON(mode.interlace);
87+ FAIL_ON(mode.margins);
88+ FAIL_ON(mode.force != DRM_FORCE_ON);
89+
90+ return 0;
91+}
92+
93 #include "drm_selftest.c"
94
95 static int __init test_drm_cmdline_init(void)