Skip to content

Commit e6980a7

Browse files
stephan-ghmripard
authored andcommitted
drm/modes: Make sure to parse valid rotation value from cmdline
A rotation value should have exactly one rotation angle. At the moment there is no validation for this when parsing video= parameters from the command line. This causes problems later on when we try to combine the command line rotation with the panel orientation. To make sure that we generate a valid rotation value: - Set DRM_MODE_ROTATE_0 by default (if no rotate= option is set) - Validate that there is exactly one rotation angle set (i.e. specifying the rotate= option multiple times is invalid) Signed-off-by: Stephan Gerhold <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b50f4f9 commit e6980a7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

drivers/gpu/drm/drm_modes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,13 @@ static int drm_mode_parse_cmdline_options(const char *str,
16981698
if (rotation && freestanding)
16991699
return -EINVAL;
17001700

1701+
if (!(rotation & DRM_MODE_ROTATE_MASK))
1702+
rotation |= DRM_MODE_ROTATE_0;
1703+
1704+
/* Make sure there is exactly one rotation defined */
1705+
if (!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK))
1706+
return -EINVAL;
1707+
17011708
mode->rotation_reflection = rotation;
17021709

17031710
return 0;

drivers/gpu/drm/selftests/drm_cmdline_selftests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cmdline_test(drm_cmdline_test_rotate_0)
5353
cmdline_test(drm_cmdline_test_rotate_90)
5454
cmdline_test(drm_cmdline_test_rotate_180)
5555
cmdline_test(drm_cmdline_test_rotate_270)
56+
cmdline_test(drm_cmdline_test_rotate_multiple)
5657
cmdline_test(drm_cmdline_test_rotate_invalid_val)
5758
cmdline_test(drm_cmdline_test_rotate_truncated)
5859
cmdline_test(drm_cmdline_test_hmirror)

drivers/gpu/drm/selftests/test-drm_cmdline_parser.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,17 @@ static int drm_cmdline_test_rotate_270(void *ignored)
856856
return 0;
857857
}
858858

859+
static int drm_cmdline_test_rotate_multiple(void *ignored)
860+
{
861+
struct drm_cmdline_mode mode = { };
862+
863+
FAIL_ON(drm_mode_parse_command_line_for_connector("720x480,rotate=0,rotate=90",
864+
&no_connector,
865+
&mode));
866+
867+
return 0;
868+
}
869+
859870
static int drm_cmdline_test_rotate_invalid_val(void *ignored)
860871
{
861872
struct drm_cmdline_mode mode = { };
@@ -888,7 +899,7 @@ static int drm_cmdline_test_hmirror(void *ignored)
888899
FAIL_ON(!mode.specified);
889900
FAIL_ON(mode.xres != 720);
890901
FAIL_ON(mode.yres != 480);
891-
FAIL_ON(mode.rotation_reflection != DRM_MODE_REFLECT_X);
902+
FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X));
892903

893904
FAIL_ON(mode.refresh_specified);
894905

@@ -913,7 +924,7 @@ static int drm_cmdline_test_vmirror(void *ignored)
913924
FAIL_ON(!mode.specified);
914925
FAIL_ON(mode.xres != 720);
915926
FAIL_ON(mode.yres != 480);
916-
FAIL_ON(mode.rotation_reflection != DRM_MODE_REFLECT_Y);
927+
FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y));
917928

918929
FAIL_ON(mode.refresh_specified);
919930

0 commit comments

Comments
 (0)