From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Hans de Goede <hdegoede@redhat.com>
Cc: linux-fbdev@vger.kernel.org,
Geert Uytterhoeven <geert@linux-m68k.org>,
linux-m68k@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/5] drm/modes: Extract drm_mode_parse_cmdline_named_mode()
Date: Thu, 14 Jul 2022 11:04:07 +0200 [thread overview]
Message-ID: <1371554419ae63cb54c2a377db0c1016fcf200bb.1657788997.git.geert@linux-m68k.org> (raw)
In-Reply-To: <cover.1657788997.git.geert@linux-m68k.org>
Extract the code to check for a named mode parameter into its own
function, to streamline the main parsing flow.
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
---
v2:
- Add Reviewed-by, Acked-by,
- Fix length check.
---
drivers/gpu/drm/drm_modes.c | 40 +++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 67773740c74c9ba0..a3df18fccb31fa77 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1749,6 +1749,29 @@ static const char * const drm_named_modes_whitelist[] = {
"PAL",
};
+static int drm_mode_parse_cmdline_named_mode(const char *name,
+ unsigned int length, bool refresh,
+ struct drm_cmdline_mode *mode)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
+ ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
+ if (ret != length)
+ continue;
+
+ if (refresh)
+ return -EINVAL; /* named + refresh is invalid */
+
+ strcpy(mode->name, drm_named_modes_whitelist[i]);
+ mode->specified = true;
+ return 0;
+ }
+
+ return 0;
+}
+
/**
* drm_mode_parse_command_line_for_connector - parse command line modeline for connector
* @mode_option: optional per connector mode option
@@ -1785,7 +1808,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
const char *options_ptr = NULL;
char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
- int i, len, ret;
+ int len, ret;
memset(mode, 0, sizeof(*mode));
mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
@@ -1823,16 +1846,11 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
}
/* First check for a named mode */
- for (i = 0; mode_end && i < ARRAY_SIZE(drm_named_modes_whitelist); i++) {
- ret = str_has_prefix(name, drm_named_modes_whitelist[i]);
- if (ret == mode_end) {
- if (refresh_ptr)
- return false; /* named + refresh is invalid */
-
- strcpy(mode->name, drm_named_modes_whitelist[i]);
- mode->specified = true;
- break;
- }
+ if (mode_end) {
+ ret = drm_mode_parse_cmdline_named_mode(name, mode_end,
+ refresh_ptr, mode);
+ if (ret)
+ return false;
}
/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
--
2.25.1
next prev parent reply other threads:[~2022-07-14 10:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 9:04 [PATCH v2 0/5] drm/modes: Command line mode selection fixes and improvements Geert Uytterhoeven
2022-07-14 9:04 ` [PATCH v2 1/5] drm/modes: parse_cmdline: Handle empty mode name part Geert Uytterhoeven
2022-07-14 12:05 ` Maxime Ripard
2022-07-14 9:04 ` Geert Uytterhoeven [this message]
2022-07-14 12:05 ` [PATCH v2 2/5] drm/modes: Extract drm_mode_parse_cmdline_named_mode() Maxime Ripard
2022-07-14 9:04 ` [PATCH v2 3/5] drm/modes: parse_cmdline: Make mode->*specified handling more uniform Geert Uytterhoeven
2022-07-14 12:05 ` Maxime Ripard
2022-07-14 9:04 ` [PATCH v2 4/5] drm/modes: Add support for driver-specific named modes Geert Uytterhoeven
2022-07-14 12:10 ` Maxime Ripard
2022-07-14 9:04 ` [PATCH v2 5/5] drm/modes: parse_cmdline: Add support for named modes containing dashes Geert Uytterhoeven
2022-07-14 12:06 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371554419ae63cb54c2a377db0c1016fcf200bb.1657788997.git.geert@linux-m68k.org \
--to=geert@linux-m68k.org \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hdegoede@redhat.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).