Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2770713ybi; Thu, 4 Jul 2019 19:08:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+DbBjr+4Vk3EvrfzShJGuXiehC7qGRxufeKEe/4AtFJ/WB0fZ4+m8BRe0xjo/dQ3n2fGV X-Received: by 2002:a17:902:9a49:: with SMTP id x9mr1486313plv.282.1562292529997; Thu, 04 Jul 2019 19:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562292529; cv=none; d=google.com; s=arc-20160816; b=BpWqZ9XIIYjU9l+Pmr1MH4rbrRPGW21XeEIG49kNREpzH7+G1wuWq9SMjyRAe6yJRW 3Xw0r23QywSk/ki3dSn5sMg0TtralZ1Avgb2lupN+iKfbliBxs2uzNgvlrPlK9dBZmi5 xhRkD39BLwMmz2bKHSC3QHWM6c7XHC0b1oE4411slizrlx625nV1MYKqOi1dQDEyEWLT QTA6HUAynb+r/FH508b9F4l3Jkv57uSjPEmYGQ3KhUkpEb8qo1BV0N5PSmu64ob9Vtse db4/w1aqme0w5V+wfuAbsaCxkm54VXE3kvx/z3LCwDA8HsRZ2pwhZynyzsBBoBV/x9LD tISQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=SHDZ4Nqx1KvLLwMpt9MdZ4HLG4wN+hdhaL6OMAI83oM=; b=YrVLrP7rsdAY2Ze8m0KpQiQbiZNl3RaGIiIoaUeBcpyaLnpHbUx6EiQe+KMxrp3Bmc dSKav/B4RU2MZWZS0b4EeMPJ37N6IXewYfIoWqMu+r0n05fXG4q+fRP6oBQPqwpHJJ6l jKqu6aakeb2c22u1zvHxYx1fMfQxJ1sTCcLxwA3Iqw3dTm7t24ZQ2pZGbk3TWtQpgTBC Hzpa7/eF+fMU90O6v43QrM9pV7PcyPngsIg6ad8okDOrds4bAWaqtsXyCgtlJ3HEyGvV v7LUOMbK1mSLZx5m/+8t78zjaM4CzRJizAoe2UAJKQEe9duyQ1sUq2k31Tfo6EBMoaVW SqNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si6154995pju.32.2019.07.04.19.08.35; Thu, 04 Jul 2019 19:08:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726765AbfGECGV (ORCPT + 99 others); Thu, 4 Jul 2019 22:06:21 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:28939 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726404AbfGECGU (ORCPT ); Thu, 4 Jul 2019 22:06:20 -0400 X-UUID: fb735ff16ef54588b3157d70f821c3d4-20190705 X-UUID: fb735ff16ef54588b3157d70f821c3d4-20190705 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1096487982; Fri, 05 Jul 2019 10:06:10 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 5 Jul 2019 10:06:04 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 5 Jul 2019 10:06:04 +0800 Message-ID: <1562292364.23476.4.camel@mtkswgap22> Subject: Re: [PATCH v2] checkpatch: add several Kconfig default value tests From: Miles Chen To: Joe Perches CC: Andy Whitcroft , , , , Yingjoe Chen Date: Fri, 5 Jul 2019 10:06:04 +0800 In-Reply-To: <53b2351f14f246b57871226f7cf45b9800e264a8.camel@perches.com> References: <20190704094024.16162-1-miles.chen@mediatek.com> <53b2351f14f246b57871226f7cf45b9800e264a8.camel@perches.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-TM-SNTS-SMTP: FDE15EDAF12E67EF2B3A8083FFDFD53EA54C2081AFEDDA8A13D8C58C1C29F02C2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-07-04 at 11:49 -0700, Joe Perches wrote: > On Thu, 2019-07-04 at 17:40 +0800, Miles Chen wrote: > > This change adds 3 Kconfig default value tests: > [] > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > [] > > @@ -3005,6 +3005,27 @@ sub process { > > "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); > > } > > > > +# discourage redundant 'default n' > > + if ($realfile =~ /Kconfig/ && > > + $line =~ /^\+\s*default n$/) { > > + WARN("DEFAULT_VALUE_STYLE", > > + "'default n' is the default value, no need to write it explicitly.\n" . $herecurr); > > + } > > + > > +# discourage quote: use default [ynm], not default "[ynm]" > > + if ($realfile =~ /Kconfig/ && > > + $rawline =~ /^\+\s*default\s*"[ynm]"/) { > > + WARN("DEFAULT_VALUE_STYLE", > > + "Use default [ynm] instead of default \"[ynm]\"\n" . $herecurr); > > + } > > + > > +# discourage default \!?EXPERT > > + if ($realfile =~ /Kconfig/ && > > + $line =~ /^\+\s*default \!?EXPERT/) { > > + WARN("DEFAULT_VALUE_STYLE", > > + "Avoid default turn on kernel configs by default !?EXPERT\n" . $herecurr); > > + } > > + > > I'd prefer to create a block for all the Kconfig file tests and > avoid multiply determining if the filename includes Kconfig so > the script runs a bit faster. > Thanks for your comments. yes, the script runs faster this way. > Also some trivial changes to the added tests with added --fix > capability. Something like: Thanks for posting the patch, I'll verify it and post as patch v3. > --- > scripts/checkpatch.pl | 139 ++++++++++++++++++++++++++++++-------------------- > 1 file changed, 85 insertions(+), 54 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 6cb99ec62000..4780149a8d30 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -2934,60 +2934,98 @@ sub process { > "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet) > } > > -# check for Kconfig help text having a real description > -# Only applies when adding the entry originally, after that we do not have > -# sufficient context to determine whether it is indeed long enough. > - if ($realfile =~ /Kconfig/ && > - # 'choice' is usually the last thing on the line (though > - # Kconfig supports named choices), so use a word boundary > - # (\b) rather than a whitespace character (\s) > - $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) { > - my $length = 0; > - my $cnt = $realcnt; > - my $ln = $linenr + 1; > - my $f; > - my $is_start = 0; > - my $is_end = 0; > - for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) { > - $f = $lines[$ln - 1]; > - $cnt-- if ($lines[$ln - 1] !~ /^-/); > - $is_end = $lines[$ln - 1] =~ /^\+/; > - > - next if ($f =~ /^-/); > - last if (!$file && $f =~ /^\@\@/); > - > - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) { > - $is_start = 1; > - } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) { > - if ($lines[$ln - 1] =~ "---help---") { > - WARN("CONFIG_DESCRIPTION", > - "prefer 'help' over '---help---' for new help texts\n" . $herecurr); > +# Kconfig tests > + if ($realfile =~ /Kconfig/) { > + # check for Kconfig help text having a real description > + # Only applies when adding the entry originally, after > + # that we do not have sufficient context to determine > + # whether it is indeed long enough. > + # 'choice' is usually the last thing on the line (though > + # Kconfig supports named choices), so use a word > + # boundary (\b) rather than a whitespace character (\s) > + if ($line =~ /^\+\s*(?:config|menuconfig|choice)\b/) { > + my $length = 0; > + my $cnt = $realcnt; > + my $ln = $linenr + 1; > + my $f; > + my $is_start = 0; > + my $is_end = 0; > + for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) { > + $f = $lines[$ln - 1]; > + $cnt-- if ($lines[$ln - 1] !~ /^-/); > + $is_end = $lines[$ln - 1] =~ /^\+/; > + > + next if ($f =~ /^-/); > + last if (!$file && $f =~ /^\@\@/); > + > + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) { > + $is_start = 1; > + } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) { > + if ($lines[$ln - 1] =~ "---help---") { > + WARN("CONFIG_DESCRIPTION", > + "prefer 'help' over '---help---' for new help texts\n" . $herecurr); > + } > + $length = -1; > + } > + > + $f =~ s/^.//; > + $f =~ s/#.*//; > + $f =~ s/^\s+//; > + next if ($f =~ /^$/); > + > + # This only checks context lines in the patch > + # and so hopefully shouldn't trigger false > + # positives, even though some of these are > + # common words in help texts > + if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice| > + if|endif|menu|endmenu|source)\b/x) { > + $is_end = 1; > + last; > } > - $length = -1; > + $length++; > + } > + if ($is_start && $is_end && $length < $min_conf_desc_length) { > + WARN("CONFIG_DESCRIPTION", > + "please write a paragraph that describes the config symbol fully\n" . $herecurr); > } > + #print "is_start<$is_start> is_end<$is_end> length<$length>\n"; > + } > > - $f =~ s/^.//; > - $f =~ s/#.*//; > - $f =~ s/^\s+//; > - next if ($f =~ /^$/); > - > - # This only checks context lines in the patch > - # and so hopefully shouldn't trigger false > - # positives, even though some of these are > - # common words in help texts > - if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice| > - if|endif|menu|endmenu|source)\b/x) { > - $is_end = 1; > - last; > +# discourage the use of boolean for type definition attributes > + if ($line =~ /^\+\s*\bboolean\b/) { > + if (WARN("CONFIG_TYPE_BOOLEAN", > + "Use of boolean is deprecated, please use bool instead\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\bboolean\b/bool/; > + } > + } > + > +# Kconfig: discourage redundant 'default n' > + if ($line =~ /^\+\s*default\s+n$/) { > + if (WARN("CONFIG_DEFAULT_VALUE_STYLE", > + "'default n' is the default value, no need to write it explicitly\n" . $herecurr) && > + $fix) { > + fix_delete_line($fixlinenr, $rawline); > } > - $length++; > } > - if ($is_start && $is_end && $length < $min_conf_desc_length) { > - WARN("CONFIG_DESCRIPTION", > - "please write a paragraph that describes the config symbol fully\n" . $herecurr); > + > +# Kconfig: discourage quoted defaults: use default [ynm], not default "[ynm]" > + if ($rawline =~ /^\+\s*default\s+"([ynm])"/) { > + if (WARN("CONFIG_DEFAULT_VALUE_STYLE", > + "Use 'default $1' not 'default \"$1\"'\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b(default\s+)"(.)"/$1$2/; > + } > + } > + > +# Kconfig: discourage using default EXPERT or !EXPERT > + if ($line =~ /^\+\s*default\s+\!?\s*EXPERT\b/) { > + WARN("CONFIG_DEFAULT_VALUE_STYLE", > + "Avoid using default EXPERT\n" . $herecurr); > } > - #print "is_start<$is_start> is_end<$is_end> length<$length>\n"; > } > +# End of Kconfig tests > + > > # check for MAINTAINERS entries that don't have the right form > if ($realfile =~ /^MAINTAINERS$/ && > @@ -3000,13 +3038,6 @@ sub process { > } > } > > -# discourage the use of boolean for type definition attributes of Kconfig options > - if ($realfile =~ /Kconfig/ && > - $line =~ /^\+\s*\bboolean\b/) { > - WARN("CONFIG_TYPE_BOOLEAN", > - "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); > - } > - > if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && > ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { > my $flag = $1; > >