From mboxrd@z Thu Jan 1 00:00:00 1970 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 F3061ECAAA1 for ; Tue, 30 Aug 2022 10:12:41 +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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ypOI/tG7s+9N9thfIJ8/sBArZdGXGF+NvtQqHrvo5zY=; b=iA6LwG/0GJo7U7 OAZkHoP+K7fwxGfL3JqLm+J+XCEHA/Dv2iH53HMGEAG/c3973ND+3JYOf6MmYPSHGvNVpBssp30Yu pZIdArcDQCIvbump/iC3etXU7Yt+hoEngOW91rIvPRcZ2a12rVhEzy/nL4jvEYzTNLSy5vW1shKJe U9bB9RZ7f3OJUl92MHESCjBa8/NOVb2tzqp0yTSP52P6AZAU8CYptUD9udE4mLARE/BURhcdudXum iYohBRdyB13nIELZulRg1kA/agciY++pzDDDtN97cpFcQNHSh1jjz3E5r2NQRUh6AGwoc+wky15Oc 44W4vniBrI2Ubo1ab9aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oSyD8-00G3Em-7W; Tue, 30 Aug 2022 10:11:12 +0000 Received: from mail-qt1-f170.google.com ([209.85.160.170]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oSy9H-00G1hI-VD for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 10:07:13 +0000 Received: by mail-qt1-f170.google.com with SMTP id cb8so8142642qtb.0 for ; Tue, 30 Aug 2022 03:07:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=B6sPmfOEwPF2h7f07mGfudT4aQe+F6kN6ETICFIZHMY=; b=PWnymlf0BHBtZhoTkVgwflDsZkEjsI8qBEFYxlp5df4QKYNgM7FnP4B91mbUW46soc TQpRLMayUxP8T16bz0xybDsSTNZIF1GkGwDEc9Ymy0VjXXnWUEgX1PF0T8RRooTpx4sI Rm9MR6d9mbZRR6LWA8Nz8yMLEojPqCeoInZYxW3snqXE7IKHLtFy5vO9ySyHgBgdQ246 IcidsjnC0Xz3rwY6oYoZ/51H6KdRtmT237j6yStS6EQG7FRrUMxvRoZt2UY9VbctU/TF KZNSX9YI3jJwhJpk8xHM7FpJYcUThaIa5gn5FeF7tLqiyJ1K2demXfDJKA1KNfSbLtaV eNVA== X-Gm-Message-State: ACgBeo1LqyEAPkXkI+zjADmFZUr7EGTgKpClVxL5YfUqCsKx3mUCpSoz g3c20tj1KYbttbonU11iqKKYfhUEzcws1Q== X-Google-Smtp-Source: AA6agR70kUhUQQyeK5MwK124OUFJX7JWfMV0lxIkd5qxVxzdpk+s+TVYfmC97D29a3Kgafzx/tCr0A== X-Received: by 2002:ac8:7d4c:0:b0:344:8bfe:22cf with SMTP id h12-20020ac87d4c000000b003448bfe22cfmr14023772qtb.580.1661854028209; Tue, 30 Aug 2022 03:07:08 -0700 (PDT) Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com. [209.85.128.170]) by smtp.gmail.com with ESMTPSA id bm2-20020a05620a198200b006b5f06186aesm7854888qkb.65.2022.08.30.03.07.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Aug 2022 03:07:07 -0700 (PDT) Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-3376851fe13so260683667b3.6 for ; Tue, 30 Aug 2022 03:07:07 -0700 (PDT) X-Received: by 2002:a25:8e84:0:b0:696:466c:baa with SMTP id q4-20020a258e84000000b00696466c0baamr10033148ybl.604.1661854027231; Tue, 30 Aug 2022 03:07:07 -0700 (PDT) MIME-Version: 1.0 References: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> <20220728-rpi-analog-tv-properties-v2-14-459522d653a7@cerno.tech> In-Reply-To: <20220728-rpi-analog-tv-properties-v2-14-459522d653a7@cerno.tech> From: Geert Uytterhoeven Date: Tue, 30 Aug 2022 12:06:55 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 14/41] drm/modes: Move named modes parsing to a separate function To: Maxime Ripard Cc: Maxime Ripard , Ben Skeggs , David Airlie , Chen-Yu Tsai , Thomas Zimmermann , Jani Nikula , Lyude Paul , Philipp Zabel , Maarten Lankhorst , Rodrigo Vivi , Tvrtko Ursulin , Jernej Skrabec , Samuel Holland , Karol Herbst , =?UTF-8?Q?Noralf_Tr=C3=B8nnes?= , Emma Anholt , Daniel Vetter , Joonas Lahtinen , Hans de Goede , Linux ARM , Phil Elwell , Intel Graphics Development , Dave Stevenson , DRI Development , Dom Cobley , Linux Kernel Mailing List , Nouveau Dev , linux-sunxi@lists.linux.dev, Mateusz Kwiatkowski X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220830_030712_048551_1DC3E7A4 X-CRM114-Status: GOOD ( 38.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Maxime, On Mon, Aug 29, 2022 at 3:13 PM Maxime Ripard wrote: > 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 Thanks for your patch! > --- a/drivers/gpu/drm/drm_modes.c > +++ b/drivers/gpu/drm/drm_modes.c > @@ -1909,6 +1909,9 @@ void drm_connector_list_update(struct drm_connector *connector) > } > EXPORT_SYMBOL(drm_connector_list_update); > > +#define STR_STRICT_EQ(str, len, cmp) \ > + ((strlen(cmp) == len) && !strncmp(str, cmp, len)) This is not part of the move, but newly added. > + > static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr, > struct drm_cmdline_mode *mode) > { > @@ -2208,6 +2211,52 @@ static const char * const drm_named_modes_whitelist[] = { > "PAL", > }; > > +static int drm_mode_parse_cmdline_named_mode(const char *name, > + unsigned int name_end, > + struct drm_cmdline_mode *cmdline_mode) > +{ > + unsigned int i; > + > + if (!name_end) > + return 0; This is already checked by the caller. > + > + /* If the name starts with a digit, it's not a named mode */ > + if (isdigit(name[0])) > + return 0; > + > + /* > + * If there's an equal sign in the name, the command-line > + * contains only an option and no mode. > + */ > + if (strnchr(name, name_end, '=')) > + return 0; > + > + /* The connection status extras can be set without a mode. */ > + if (STR_STRICT_EQ(name, name_end, "d") || > + STR_STRICT_EQ(name, name_end, "D") || > + STR_STRICT_EQ(name, name_end, "e")) > + return 0; These checks are not part of the move, and should probably be added in a separate patch. > + > + /* > + * We're sure we're a named mode at that point, iterate over the > + * list of modes we're aware of. > + */ > + 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 1; > + } > + > + return -EINVAL; > +} > + > /** > * drm_mode_parse_command_line_for_connector - parse command line modeline for connector > * @mode_option: optional per connector mode option > @@ -2244,7 +2293,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; > @@ -2285,17 +2334,19 @@ 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 */ > > - 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, mode); > + if (ret < 0) > + return false; > + > + /* > + * 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 (ret && refresh_ptr) > + return false; > } > > /* No named mode? Check for a normal mode argument, e.g. 1024x768 */ > Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel