Skip to content

Commit 3764137

Browse files
committed
drm/modes: Introduce a whitelist for the named modes
The named modes support has introduced a number of glitches that were in part due to the fact that the parser will take any string as a named mode. Since we shouldn't have a lot of options there (and they should be pretty standard), let's introduce a whitelist of the available named modes so that the kernel can differentiate between a poorly formed command line and a named mode. Signed-off-by: Maxime Ripard <[email protected]> Tested-by: Thomas Graichen <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 728a257 commit 3764137

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/gpu/drm/drm_modes.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,22 @@ static int drm_mode_parse_cmdline_options(char *str, size_t len,
16771677
return 0;
16781678
}
16791679

1680+
static const char *drm_named_modes_whitelist[] = {
1681+
"NTSC",
1682+
"PAL",
1683+
};
1684+
1685+
static bool drm_named_mode_is_in_whitelist(const char *mode, unsigned int size)
1686+
{
1687+
int i;
1688+
1689+
for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++)
1690+
if (!strncmp(mode, drm_named_modes_whitelist[i], size))
1691+
return true;
1692+
1693+
return false;
1694+
}
1695+
16801696
/**
16811697
* drm_mode_parse_command_line_for_connector - parse command line modeline for connector
16821698
* @mode_option: optional per connector mode option
@@ -1794,6 +1810,10 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
17941810
if (named_mode) {
17951811
if (mode_end + 1 > DRM_DISPLAY_MODE_LEN)
17961812
return false;
1813+
1814+
if (!drm_named_mode_is_in_whitelist(name, mode_end))
1815+
return false;
1816+
17971817
strscpy(mode->name, name, mode_end + 1);
17981818
} else {
17991819
ret = drm_mode_parse_cmdline_res_mode(name, mode_end,

0 commit comments

Comments
 (0)