From patchwork Fri Jul 29 16:34:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12932634 X-Patchwork-Delegate: neil.armstrong@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 284C5C00144 for ; Fri, 29 Jul 2022 16:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n+UDSICfpxBGze83d38dE3y+2hkFyzwkSvU2P3j2kHg=; b=qnb1WK/MXGRPxJ XEJov8IY2k7TdKlBw70m1Aqzo1BAEZfYRn+t/YV/ToHAW355pjX0TTkGaRR1VqQNMvlcC7DtH7IuW ghaJN7FLbqR1AdbeexbRHZtscfCsLPhLJapAOgWjFtUFJ9Mx7UYP1w4Gc/OJAfyvMp+rDReeotG3K L2jnJ7Ugqj8jSHG+L3VOBFtQSzxEqzUCMoVelfQGmTOy7MOJDkAlVhofXCnCxeKYiKtM+pk4dKDqs nPRsiWNBhCmKYRqgBK+SpWe4sO9VOqsM8sWSGoTBprgiqNV2CGz+DHvv3qhK9DMOOvUzXYPjIjZK1 le21odtJ2nQk8oSEkARA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHT3Y-006VrW-Ie; Fri, 29 Jul 2022 16:41:44 +0000 Received: from new4-smtp.messagingengine.com ([66.111.4.230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHSy1-006S6J-51; Fri, 29 Jul 2022 16:36:03 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 6A46C58093D; Fri, 29 Jul 2022 12:36:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 29 Jul 2022 12:36:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1659112560; x= 1659119760; bh=st2NK37KTfySqs+WWdYxjBL07hSVh6varfy6HltspJc=; b=r dFEjrH53Yv87FiCgiK7WnA0uvSnLZ3ZRT8ZwaJcinNzyBTzUSg4dbLcYSVAsR5UO x2hngPpmPwPKGdP6DW8u9/RX+nmNLHaCSggbVJ+F6po0QtBUk5sbR7eblJlzgmMc 8SV/xVsnszvlW3QHtZ41/7y6XPYlifM1kzPJ27qXSZy8oNkegEwlCJzwuWuS2Cvk Kjx/XdbZqfw1vx2ke9RIzVn6jnI4EZzYbh5unk1j2VuePiwKjfBRN9jGpcoz4/A1 ajsXuIjjsCBkYkpr4ieQM/uhda30iyGsd8Q6JMujbF0bu1VLzxxGqTY4iHn2T9AL hC6TT43I9cdruUMOKY6uw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1659112560; x= 1659119760; bh=st2NK37KTfySqs+WWdYxjBL07hSVh6varfy6HltspJc=; b=y 5ZHinuWkTWspJfi/IPrezlrOZ5v5DBOq+BvMGGrotoC9RjPRRZ4a4DlDqGQWBEHs hvFK/PicN7qqkUJDAoMEKbX3UwCH+GbHAuZxZd85eybIJ/gPZup7qd4xyxi/g4MZ EK+yYiGTpEvyFLkxEQYKfR+ChSGPlYqNZWoCD8F+H3dC1Yupv/QViaRsOy/M8ltz mpA5QLWjL/I+XjozTJrrlBoxcbLOWzSLvm+h06/IPk/YtofcZ2lYNJP9wZUJNVkR 8XenPK451CPGOMGkXrG+mSlrIi3H0zmamqFP2P3YVV5T9Dy5ql1BrjXe8SOCeW6k svDNDJa6aEbtT5SsnDbfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddujedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfgggtoffgsehtkeertdertdejnecuhfhrohhmpefo rgigihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecugg ftrfgrthhtvghrnhepgfffgfetffduudelhfevieffffduleevgfegkeeutefgffejheel leekjeefhfejnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrh homhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Jul 2022 12:35:59 -0400 (EDT) From: Maxime Ripard To: Jernej Skrabec , Martin Blumenstingl , Chen-Yu Tsai , Philipp Zabel , Jerome Brunet , Samuel Holland , Thomas Zimmermann , Daniel Vetter , Emma Anholt , David Airlie , Maarten Lankhorst , =?utf-8?q?Noralf_Tr?= =?utf-8?q?=C3=B8nnes?= , Kevin Hilman , Neil Armstrong , Maxime Ripard Cc: Maxime Ripard , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Phil Elwell , Mateusz Kwiatkowski , linux-arm-kernel@lists.infradead.org, Geert Uytterhoeven , Dave Stevenson , linux-amlogic@lists.infradead.org, dri-devel@lists.freedesktop.org, Dom Cobley Subject: [PATCH v1 09/35] drm/modes: Move named modes parsing to a separate function Date: Fri, 29 Jul 2022 18:34:52 +0200 Message-Id: <20220728-rpi-analog-tv-properties-v1-9-3d53ae722097@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> References: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> MIME-Version: 1.0 X-Mailer: b4 0.10.0-dev-49460 X-Developer-Signature: v=1; a=openpgp-sha256; l=2488; i=maxime@cerno.tech; h=from:subject:message-id; bh=jeXmsF+0yQoip9VjnXEGiKY2SAbOvZx7rBy39YwT/5A=; b=owGbwMvMwCHc4XzqmfnC7acZT6slMSQ94VHS9vnqUd56XL2tMM13vuv60m8Bjo5TH1s4Vey4rWKR uXVrRykLgzAHg6yYIst1wbd2fGFRbhE8HzbDzGFlAhnCwMUpABPRvMvI0CATOj3A4sK+03cCi5d1dR zpSLijNfHqhg2eAgkrXKzlJzMybDxbsn39K6/o+y41j2yXeeoIsn9tl5bkZvj5QbFAxKxGCwA= X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_093601_314186_501371A5 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The current construction of the named mode parsing doesn't allow to extend it easily. Let's move it to a separate function so we can add more parameters and modes. Signed-off-by: Maxime Ripard diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index 06a006e0b2e3..e85099df0326 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -1773,6 +1773,28 @@ static const char * const drm_named_modes_whitelist[] = { "PAL", }; +static bool drm_mode_parse_cmdline_named_mode(const char *name, + unsigned int name_end, + struct drm_cmdline_mode *cmdline_mode) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i++) { + int ret; + + ret = str_has_prefix(name, drm_named_modes_whitelist[i]); + if (ret != name_end) + continue; + + strcpy(cmdline_mode->name, drm_named_modes_whitelist[i]); + cmdline_mode->specified = true; + + return true; + } + + return false; +} + /** * drm_mode_parse_command_line_for_connector - parse command line modeline for connector * @mode_option: optional per connector mode option @@ -1809,7 +1831,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; @@ -1848,18 +1870,14 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, parse_extras = true; } - /* First check for a named mode */ - for (i = 0; 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 */ + /* + * Having a mode that starts by a letter (and thus is named) and + * an at-sign (used to specify a refresh rate) is disallowed. + */ + if (!isdigit(name[0]) && refresh_ptr) + return false; - strcpy(mode->name, drm_named_modes_whitelist[i]); - mode->specified = true; - break; - } - } + drm_mode_parse_cmdline_named_mode(name, mode_end, mode); /* No named mode? Check for a normal mode argument, e.g. 1024x768 */ if (!mode->specified && isdigit(name[0])) {