From patchwork Tue Jun 28 12:27:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 12898208 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E22ADCCA483 for ; Tue, 28 Jun 2022 12:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345722AbiF1M20 (ORCPT ); Tue, 28 Jun 2022 08:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345736AbiF1M2S (ORCPT ); Tue, 28 Jun 2022 08:28:18 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC265175AC; Tue, 28 Jun 2022 05:28:09 -0700 (PDT) Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LXP4F0H3Tz689Py; Tue, 28 Jun 2022 20:27:25 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 28 Jun 2022 14:28:07 +0200 From: Roberto Sassu To: , , , , , , , , CC: , , , , , , Roberto Sassu Subject: [PATCH v6 3/5] scripts: Handle unsigned type prefix in bpf_doc.py Date: Tue, 28 Jun 2022 14:27:48 +0200 Message-ID: <20220628122750.1895107-4-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220628122750.1895107-1-roberto.sassu@huawei.com> References: <20220628122750.1895107-1-roberto.sassu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml751-chm.china.huawei.com (10.201.108.201) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: While unsigned long is an accepted parameter type, the regular expression validating helper prototypes does not correctly take into account types composed by multiple words. The regular expression: ((const )?(struct )?(\w+|\.\.\.)( \**\w+)?) accepts only const and struct as prefix before the type. The following part of the regular expression expects a word with [a-zA-Z0-9_] characters (without space), so it would get just unsigned. Parsing words with \w+ in greedy mode makes the regular expression work even if the type is composed by two words, but not always. It wouldn't have been the case in possessive mode \w++ (don't give back characters to match the regular expression). Simply adding unsigned as possible prefix is not correct, as the struct unsigned combination is not legal. Make instead struct and unsigned as alternatives, so that the following new combinations are legal: unsigned type struct type const unsigned type and not: struct unsigned type The regular expression is a preliminary check. The type, other than being legal, must be also present in the known_types array. Don't mention the change in the regular expression description, as it is assumed that type implies also multiple words types. At this point, don't switch from greedy to possessive mode (\w+ -> \w++) to avoid partial parsing of the type of helper parameters, as this functionality has only been added recently in Python 3.11. Signed-off-by: Roberto Sassu --- scripts/bpf_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index a0ec321469bd..25e79d811487 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -124,7 +124,7 @@ class HeaderParser(object): # - Same as above, with "const" and/or "struct" in front of type # - "..." (undefined number of arguments, for bpf_trace_printk()) # There is at least one term ("void"), and at most five arguments. - p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') + p = re.compile(' \* ?((.+) \**\w+\((((const )?((struct )|(unsigned )?)(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') capture = p.match(self.line) if not capture: raise NoHelperFound