Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6107978ybi; Wed, 31 Jul 2019 08:28:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqytEA+uH4XlIPkoXjgpp9XBzT1QWkn9tvRRA+6p6/k6l51YtplDpdy+MySR/2caAhDC6wRY X-Received: by 2002:aa7:9afc:: with SMTP id y28mr47217456pfp.252.1564586891228; Wed, 31 Jul 2019 08:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564586891; cv=none; d=google.com; s=arc-20160816; b=tBGylqPVmROT/S5S3ZKgSrVWPTHaX39ngPW0xPZecDoJVpyod3nVHELJyJ4Des+BOC iNQ01z+dHC4w56hzanp48DjBzIKDGCBeqK1MKO8UQTSPohWPPFRDIW3m7AGgfbF77bRn NKIid3DZO6Ga3SOX4PB8mD9RYu8XPsH9jx2EwNRvOf3KCgX4LmT5qnoZoVFZ4GpzKver bZWwJCO7voq9AHCY+zjfqWypscxPnDGnN9/qIbu1APa1tzxN6qxIUvt62FDXFWQUT2CA RPaugTwMCkayXlgsUahrJ4OdahqaHe5G/iF6DDWJTmit8eSXhp3NgwntoSDaFx5ieO08 Xx0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=YuoxT5U3zMoT+3f7cAMJb05hqS2FjtQvry0yILN2/tM=; b=l9lMXEO1K71SYwGPJyA0z9VTe8xUa9IlXovpc+L5qcW2kon+2HhtiwCzynJfbSNky6 l7iO/q50EiWMOnvyd+1EtFiG11vo7+qWDpsjO9zQ44/mcI/3PGxMOYwbQxSQsJrpcSid G1KaNIyHpwlpeIZ8v+5JBC5SBVriQBjFWvIxsVAtOWKoBXQ3A+DbyPaXBXXgR46hiDRF CYJenB9tGgFZTXgS9aRA5M3HBjxDvcVd40bfljC6T5ohzUyL5nPp/wcnhfd7n4wgIFJA 5wpHUqsIVw/vbjvFY3kNCrIjzkTQHQlsUS0DKpqfyGhs4u65h6OwmO5zeWnVGe0L/fa8 XYRw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l184si58935200pgd.203.2019.07.31.08.27.56; Wed, 31 Jul 2019 08:28:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbfGaPSW (ORCPT + 99 others); Wed, 31 Jul 2019 11:18:22 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:63362 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726859AbfGaPSV (ORCPT ); Wed, 31 Jul 2019 11:18:21 -0400 X-UUID: fec258378a214b9681d644dcc4839ef7-20190731 X-UUID: fec258378a214b9681d644dcc4839ef7-20190731 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0707 with TLS) with ESMTP id 11032262; Wed, 31 Jul 2019 23:13:11 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 31 Jul 2019 23:13:10 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 31 Jul 2019 23:13:10 +0800 From: Miles Chen To: Andy Whitcroft , Joe Perches CC: , , , Miles Chen , Yingjoe Chen Subject: [PATCH v3] checkpatch: add several Kconfig default value tests Date: Wed, 31 Jul 2019 23:13:09 +0800 Message-ID: <20190731151309.1167-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change adds 3 Kconfig default value tests. Repost patch v3 (Follow Joe's suggestion in v2) 1. discourage default n cases: e.g., default n 2. discourage default "[ynm]" cases: e.g., arch/powerpc/Kconfig: default "y" if PPC_POWERNV arch/powerpc/Kconfig: default "y" if PPC_POWERNV arch/powerpc/Kconfig: default "n" drivers/auxdisplay/Kconfig: default "n" drivers/crypto/Kconfig: default "m" drivers/rapidio/devices/Kconfig: default "n" 3. discourage default EXPERT or default !EXPERT cases: e.g., drivers/hid/Kconfig: default !EXPERT tested cases: default m default n if ALPHA_EV5 || ALPHA_EV56 || (ALPHA_EV4 && !ALPHA_LCA) default y if ALPHA_QEMU default n if PPC_POWERNV default n default EXPERT default !EXPERT default "m" default "n" default "y" if EXPERT default "y" if PPC_POWERNV test result: WARNING: 'default n' is the default value, no need to write it explicitly + default n WARNING: Avoid using default EXPERT + default EXPERT WARNING: Avoid using default EXPERT + default !EXPERT WARNING: Use 'default m' not 'default "m"' + default "m" WARNING: Use 'default n' not 'default "n"' + default "n" WARNING: Use 'default y' not 'default "y"' + default "y" if EXPERT WARNING: Use 'default y' not 'default "y"' + default "y" if PPC_POWERNV test --fix capability: default n => delete line default "m" => default m default "n" => default n default "y" if EXPERT => default y if EXPERT default "y" if PPC_POWERNV => default y if PPC_POWERNV default !EXPERT => no change default EXPERT => no change Change since v1: discourage default n$ discourage default "[ynm]" discourage default \!?EXPERT Change since v2: test Kconfig in a single block print precise message such as 'default "m"', not 'default "[ynm]"' provide --fix capability Cc: Joe Perches Cc: Yingjoe Chen Signed-off-by: Miles Chen --- scripts/checkpatch.pl | 139 ++++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 54 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 93a7edfe0f05..b080eea68cf6 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2932,60 +2932,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$/ && @@ -2998,13 +3036,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; -- 2.18.0