Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3077618ybt; Mon, 22 Jun 2020 14:29:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyd4muhVal/6OoYAdYJLjHLpLV9/JvLc1BTVbHlOoI8UV06NbSA0fspuWrp9eWwce6fK7jj X-Received: by 2002:a17:906:824c:: with SMTP id f12mr7998941ejx.443.1592861356259; Mon, 22 Jun 2020 14:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592861356; cv=none; d=google.com; s=arc-20160816; b=XYDhnAszPocBD9Su4uqlpNhgs0jm6cbzQX9vZSHnd/3XLIocK4lH3AWLhDH9FLr1dj BTYJSNKPPduIeIi0/fVDUAAG75hYje19uCtBCy34BB1uosjFlC5oG3cR3mU98dCcD7mw PDk8Uu0LpwP8cZl3wSaka2xJgev1bsDon9TeGGCn4q6PpBbKytpIhilaD9smI6qUD3uv udIIFN1c+5XKwjVl2KQZFo0+/80Ll4LxcXqCMoj162bpX9rcvDzq6vOOaXKl823WPFhc yUG9Z1ApzQ6t7tIybR+DELXjqkfkhWGcGHOoPAFkDylDT2vzswajEtMhNJaMYMzrOvoI 6j3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=XDv8x2kV/ehZjUQgTC4RAzhkAF72B8Nd5ATtOryB1q4=; b=tj6CDACV998D8TI2uM2yq9KC4Pgj+6O2/TIuamu4hnw3u+rKXLNm1z4gz7DxJ6oaWM UWf2cxZbX0eX4HUKedM2ooBZlVeG8hB907MfycL/kptHDy/tuTdhktptCRlVSyzxj9lU BHyGlmgkhrGX5yLfKDM4RwpCLiJBg7mzABcA+RfjTkNwhypvdiTeWOIdJUAmvKF55bNO wb7zZ8XiIt9GHo2+ncP/BujxnVPfvbDj5pc3WIji8eFJHXl8Fpi6kqfQJ8druShFkzVS BVuxW5o/Xm2Il65HEGmENI2CB4hDPUJm1BX9+Nh49pAYlxVBwdqjT4LCb8/NdydEslFY /KzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si283437edc.220.2020.06.22.14.28.52; Mon, 22 Jun 2020 14:29:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730559AbgFVVYu (ORCPT + 99 others); Mon, 22 Jun 2020 17:24:50 -0400 Received: from smtprelay0192.hostedemail.com ([216.40.44.192]:51818 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728555AbgFVVYu (ORCPT ); Mon, 22 Jun 2020 17:24:50 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id EB19718029134; Mon, 22 Jun 2020 21:24:48 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3653:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:7875:7903:8957:9010:10004:10400:11232:11658:11914:12043:12114:12296:12297:12740:12760:12895:13160:13229:13255:13439:14093:14097:14181:14659:14721:21063:21080:21221:21324:21451:21627:21795:30012:30034:30051:30054:30056:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: sink53_2c02d6f26e36 X-Filterd-Recvd-Size: 3649 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA; Mon, 22 Jun 2020 21:24:47 +0000 (UTC) Message-ID: <8a218fa14cc2e1690df32d278c82587c7507a820.camel@perches.com> Subject: Re: [PATCH] checkpatch: fix CONST_STRUCT when const_structs.checkpatch is missing From: Joe Perches To: Quentin Monnet , Andy Whitcroft , Andrew Morton Cc: linux-kernel@vger.kernel.org Date: Mon, 22 Jun 2020 14:24:47 -0700 In-Reply-To: <20200622204844.21030-1-quentin@isovalent.com> References: <20200622204844.21030-1-quentin@isovalent.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.2-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-06-22 at 21:48 +0100, Quentin Monnet wrote: > Checkpatch reports warnings when some specific structs are not declared > as const in the code. The list of structs to consider was initially > defined in the checkpatch.pl script itself, but it was later moved to an > external file (scripts/const_structs.checkpatch). This introduced two > minor issues: > > - When file scripts/const_structs.checkpatch is not present (for > example, if checkpatch is run outside of the kernel directory with the > "--no-tree" option), a warning is printed to stderr to tell the user > that "No structs that should be const will be found". This is fair, > but the warning is printed unconditionally, even if the option > "--ignore CONST_STRUCT" is passed. In the latter case, we explicitly > ask checkpatch to skip this check, so no warning should be printed. > > - When scripts/const_structs.checkpatch is missing, or even when trying > to silence the warning by adding an empty file, $const_structs is set > to "", and the regex used for finding structs that should be const, > "$line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/)", matches all > structs found in the code, thus reporting a number of false positives. > > Let's fix the first item by skipping scripts/const_structs.checkpatch > processing if "CONST_STRUCT" checks are ignored, and the second one by > skipping the test if $const_structs is an empty string. > > Fixes: bf1fa1dae68e ("checkpatch: externalize the structs that should be const") Probably not worthy of a Fixes: line, as that's generally used for backporting, but OK by me. > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -781,8 +781,10 @@ sub read_words { > } > > my $const_structs = ""; This might be a tiny bit faster/less cpu using: my $const_structs; > -read_words(\$const_structs, $conststructsfile) > - or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; > +if (show_type("CONST_STRUCT")) { > + read_words(\$const_structs, $conststructsfile) > + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; > +} > > my $typeOtherTypedefs = ""; > if (length($typedefsfile)) { > @@ -6660,7 +6662,8 @@ sub process { > > # check for various structs that are normally const (ops, kgdb, device_tree) > # and avoid what seem like struct definitions 'struct foo {' > - if ($line !~ /\bconst\b/ && > + if ($const_structs ne "" && instead testing if (defined($const_structs) && > + $line !~ /\bconst\b/ && > $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { > WARN("CONST_STRUCT", > "struct $1 should normally be const\n" . $herecurr);