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 X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6216C10F0E for ; Thu, 18 Apr 2019 16:12:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 82C5A20835 for ; Thu, 18 Apr 2019 16:12:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lFBb5WPS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tronnes.org header.i=@tronnes.org header.b="usQF6pFn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82C5A20835 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tronnes.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BRYi1qTKk70F1jxqrl44Hs9pLolL2Rkignq8MhKMo+M=; b=lFBb5WPSnPfgn/ 3CyRVeXzu65M6RM5AesLqTSa2heGiaD5csW6sbJ9rZHfPDs61l2RpQ7NV2aX+t8b47Iinc8yWmNYz LGlJGv/RmEpDyqWFsG6IJdax5UShBPbgxrlNVpLnQ4WL2YNLsIwNyONP+4z+FnBUv7vkdGHmCM1Oi rhO3QNgKPXFTl/TMJVz3aSPqVaqSs6biCJY4EMOa5qPtryrqdXjXb/0LxKIs7zwbtzTLChodf21I7 cV2knWkJ9N8Zucjb703reRrrOeP/RRwlJdJE/mPybEqpJygO4CgiK6IazejbvpRU6mOyEQDsPay28 ffI6vxrK2j+259VQLUeg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH9dv-000334-6s; Thu, 18 Apr 2019 16:12:07 +0000 Received: from smtp.domeneshop.no ([2a01:5b40:0:3005::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH9do-00032V-Am for linux-arm-kernel@lists.infradead.org; Thu, 18 Apr 2019 16:12:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=oQnySsF37rARPoNjpZZfahMTcntLvx6rIZHg0Upya6A=; b=usQF6pFntiiivmBgb9owEBUvOJqj8pd9iNJ9YySA3VkrYN7sYwq1O8QF4ehnolzzqR+9ybpxTqC5WsnDfkxlJiJ87IYUrMgPEJ8DlffFW2d3UDbAOhoZPiDBWfnBC3yq5Nkel668a+hyjKZfDKZslWyQ19yG2DQyc76iPi8zCgh2E6SyKTu45XiYdeQo3EAQeRia7Ry4EVsEfoNQk5OTsIdQ4ZpK1/I+qOEPtr/Qu6dp8JT/R5kIH3K/6iO6nt/LfIQSPGw5l8qlAVCuY835HafGcTTd1wRcJCP2s9YwE4Y1ILiCIPHY9KjEpzQDE96q0CHFQlbSU9vmjOWKm1QVwQ==; Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:63231 helo=[192.168.10.179]) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1hH9di-0001XM-Pn; Thu, 18 Apr 2019 18:11:54 +0200 Subject: Re: [PATCH v3 1/6] drm/modes: Rewrite the command line parser To: Maxime Ripard , Maarten Lankhorst , Sean Paul , Daniel Vetter , David Airlie References: <500140e56478f2b91c30ff7389a4444b427b1dfd.1555591281.git-series.maxime.ripard@bootlin.com> From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= Message-ID: <2d07dee0-2907-c6bb-31b0-eb151bc513bd@tronnes.org> Date: Thu, 18 Apr 2019 18:11:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <500140e56478f2b91c30ff7389a4444b427b1dfd.1555591281.git-series.maxime.ripard@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190418_091200_732624_D6A80F4C X-CRM114-Status: GOOD ( 25.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eben@raspberrypi.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Eric Anholt , Thomas Petazzoni , Maxime Ripard , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Den 18.04.2019 14.41, skrev Maxime Ripard: > From: Maxime Ripard > > Rewrite the command line parser in order to get away from the state machine > parsing the video mode lines. > > Hopefully, this will allow to extend it more easily to support named modes > and / or properties set directly on the command line. > > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_modes.c | 305 +++++++++++++++++++++++-------------- > 1 file changed, 190 insertions(+), 115 deletions(-) > > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c > index 56f92a0bba62..3f89198f0891 100644 > --- a/drivers/gpu/drm/drm_modes.c > +++ b/drivers/gpu/drm/drm_modes.c > @@ -30,6 +30,7 @@ > * authorization from the copyright holder(s) and author(s). > */ > > +#include > #include > #include > #include > @@ -1405,6 +1406,131 @@ void drm_connector_list_update(struct drm_connector *connector) > } > EXPORT_SYMBOL(drm_connector_list_update); > > +static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr, > + struct drm_cmdline_mode *mode) > +{ > + if (str[0] != '-') > + return -EINVAL; > + > + mode->bpp = simple_strtol(str + 1, end_ptr, 10); What happens if this is not a number? I didn't find a test for that in your unit tests. The same goes for _refresh(). > + mode->bpp_specified = true; > + > + return 0; > +} > + > +static int drm_mode_parse_cmdline_refresh(const char *str, char **end_ptr, > + struct drm_cmdline_mode *mode) > +{ > + if (str[0] != '@') > + return -EINVAL; > + > + mode->refresh = simple_strtol(str + 1, end_ptr, 10); > + mode->refresh_specified = true; > + > + return 0; > +} > + > +static int drm_mode_parse_cmdline_extra(const char *str, int length, > + struct drm_connector *connector, > + struct drm_cmdline_mode *mode) > +{ > + int i; > + > + for (i = 0; i < length; i++) { > + switch (str[i]) { > + case 'i': > + mode->interlace = true; > + break; > + case 'm': > + mode->margins = true; > + break; > + case 'D': > + if (mode->force != DRM_FORCE_UNSPECIFIED) > + return -EINVAL; > + > + if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) && > + (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)) > + mode->force = DRM_FORCE_ON; > + else > + mode->force = DRM_FORCE_ON_DIGITAL; > + break; > + case 'd': > + if (mode->force != DRM_FORCE_UNSPECIFIED) > + return -EINVAL; > + > + mode->force = DRM_FORCE_OFF; > + break; > + case 'e': > + if (mode->force != DRM_FORCE_UNSPECIFIED) > + return -EINVAL; > + > + mode->force = DRM_FORCE_ON; > + break; > + default: > + return -EINVAL; > + } > + } > + > + return 0; > +} > + > +static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length, > + bool extras, > + struct drm_connector *connector, > + struct drm_cmdline_mode *mode) > +{ > + bool rb = false, cvt = false; > + int xres = 0, yres = 0; > + int remaining, i; > + char *end_ptr; > + > + xres = simple_strtol(str, &end_ptr, 10); > + > + if (end_ptr[0] != 'x') 'x600' looks to be a valid resolution here, so I think: if (str == end_ptr || end_ptr[0] != 'x') > + return -EINVAL; > + end_ptr++; > + > + yres = simple_strtol(end_ptr, &end_ptr, 10); > + > + remaining = length - (end_ptr - str); > + if (remaining < 0) > + return -EINVAL; Maybe some unit tests: '1024xy' and '1024x', to verify that this does indeed require a number for yres. Noralf. > + > + for (i = 0; i < remaining; i++) { > + switch (end_ptr[i]) { > + case 'M': > + cvt = true; > + break; > + case 'R': > + rb = true; > + break; > + default: > + /* > + * Try to pass that to our extras parsing > + * function to handle the case where the > + * extras are directly after the resolution > + */ > + if (extras) { > + int ret = drm_mode_parse_cmdline_extra(end_ptr + i, > + 1, > + connector, > + mode); > + if (ret) > + return ret; > + } else { > + return -EINVAL; > + } > + } > + } > + > + mode->xres = xres; > + mode->yres = yres; > + mode->cvt = cvt; > + mode->rb = rb; > + > + return 0; > +} > + > /** > * drm_mode_parse_command_line_for_connector - parse command line modeline for connector > * @mode_option: optional per connector mode option > @@ -1431,13 +1557,12 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, > struct drm_cmdline_mode *mode) > { > const char *name; > - unsigned int namelen; > - bool res_specified = false, bpp_specified = false, refresh_specified = false; > - unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0; > - bool yres_specified = false, cvt = false, rb = false; > - bool interlace = false, margins = false, was_digit = false; > - int i; > - enum drm_connector_force force = DRM_FORCE_UNSPECIFIED; > + bool parse_extras = false; > + unsigned int bpp_off = 0, refresh_off = 0; > + unsigned int mode_end = 0; > + char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL; > + char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL; > + int ret; > > #ifdef CONFIG_FB > if (!mode_option) > @@ -1450,127 +1575,77 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, > } > > name = mode_option; > - namelen = strlen(name); > - for (i = namelen-1; i >= 0; i--) { > - switch (name[i]) { > - case '@': > - if (!refresh_specified && !bpp_specified && > - !yres_specified && !cvt && !rb && was_digit) { > - refresh = simple_strtol(&name[i+1], NULL, 10); > - refresh_specified = true; > - was_digit = false; > - } else > - goto done; > - break; > - case '-': > - if (!bpp_specified && !yres_specified && !cvt && > - !rb && was_digit) { > - bpp = simple_strtol(&name[i+1], NULL, 10); > - bpp_specified = true; > - was_digit = false; > - } else > - goto done; > - break; > - case 'x': > - if (!yres_specified && was_digit) { > - yres = simple_strtol(&name[i+1], NULL, 10); > - yres_specified = true; > - was_digit = false; > - } else > - goto done; > - break; > - case '0' ... '9': > - was_digit = true; > - break; > - case 'M': > - if (yres_specified || cvt || was_digit) > - goto done; > - cvt = true; > - break; > - case 'R': > - if (yres_specified || cvt || rb || was_digit) > - goto done; > - rb = true; > - break; > - case 'm': > - if (cvt || yres_specified || was_digit) > - goto done; > - margins = true; > - break; > - case 'i': > - if (cvt || yres_specified || was_digit) > - goto done; > - interlace = true; > - break; > - case 'e': > - if (yres_specified || bpp_specified || refresh_specified || > - was_digit || (force != DRM_FORCE_UNSPECIFIED)) > - goto done; > > - force = DRM_FORCE_ON; > - break; > - case 'D': > - if (yres_specified || bpp_specified || refresh_specified || > - was_digit || (force != DRM_FORCE_UNSPECIFIED)) > - goto done; > + if (!isdigit(name[0])) > + return false; > > - if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) && > - (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)) > - force = DRM_FORCE_ON; > - else > - force = DRM_FORCE_ON_DIGITAL; > - break; > - case 'd': > - if (yres_specified || bpp_specified || refresh_specified || > - was_digit || (force != DRM_FORCE_UNSPECIFIED)) > - goto done; > + /* Try to locate the bpp and refresh specifiers, if any */ > + bpp_ptr = strchr(name, '-'); > + if (bpp_ptr) { > + bpp_off = bpp_ptr - name; > + mode->bpp_specified = true; > + } > > - force = DRM_FORCE_OFF; > - break; > - default: > - goto done; > - } > + refresh_ptr = strchr(name, '@'); > + if (refresh_ptr) { > + refresh_off = refresh_ptr - name; > + mode->refresh_specified = true; > } > > - if (i < 0 && yres_specified) { > - char *ch; > - xres = simple_strtol(name, &ch, 10); > - if ((ch != NULL) && (*ch == 'x')) > - res_specified = true; > - else > - i = ch - name; > - } else if (!yres_specified && was_digit) { > - /* catch mode that begins with digits but has no 'x' */ > - i = 0; > + /* Locate the end of the name / resolution, and parse it */ > + if (bpp_ptr && refresh_ptr) { > + mode_end = min(bpp_off, refresh_off); > + } else if (bpp_ptr) { > + mode_end = bpp_off; > + } else if (refresh_ptr) { > + mode_end = refresh_off; > + } else { > + mode_end = strlen(name); > + parse_extras = true; > } > -done: > - if (i >= 0) { > - pr_warn("[drm] parse error at position %i in video mode '%s'\n", > - i, name); > - mode->specified = false; > + > + ret = drm_mode_parse_cmdline_res_mode(name, mode_end, > + parse_extras, > + connector, > + mode); > + if (ret) > return false; > - } > + mode->specified = true; > > - if (res_specified) { > - mode->specified = true; > - mode->xres = xres; > - mode->yres = yres; > + if (bpp_ptr) { > + ret = drm_mode_parse_cmdline_bpp(bpp_ptr, &bpp_end_ptr, mode); > + if (ret) > + return false; > } > > - if (refresh_specified) { > - mode->refresh_specified = true; > - mode->refresh = refresh; > + if (refresh_ptr) { > + ret = drm_mode_parse_cmdline_refresh(refresh_ptr, > + &refresh_end_ptr, mode); > + if (ret) > + return false; > } > > - if (bpp_specified) { > - mode->bpp_specified = true; > - mode->bpp = bpp; > + /* > + * Locate the end of the bpp / refresh, and parse the extras > + * if relevant > + */ > + if (bpp_ptr && refresh_ptr) > + extra_ptr = max(bpp_end_ptr, refresh_end_ptr); > + else if (bpp_ptr) > + extra_ptr = bpp_end_ptr; > + else if (refresh_ptr) > + extra_ptr = refresh_end_ptr; > + > + if (extra_ptr) { > + int remaining = strlen(name) - (extra_ptr - name); > + > + /* > + * We still have characters to process, while > + * we shouldn't have any > + */ > + if (remaining > 0) > + return false; > } > - mode->rb = rb; > - mode->cvt = cvt; > - mode->interlace = interlace; > - mode->margins = margins; > - mode->force = force; > > return true; > } > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel