Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp705245ybv; Thu, 13 Feb 2020 08:04:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxLGimExzFJ8dM0EJLyJxCyxA2hrlkmIqy11FtDG6R85pwKplE493m/3IlgkuM6up8o5z39 X-Received: by 2002:aca:ab52:: with SMTP id u79mr3170452oie.145.1581609885261; Thu, 13 Feb 2020 08:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581609885; cv=none; d=google.com; s=arc-20160816; b=tC6WftAvUA5I6fU6jofYjHj/0+bGZYDNggPAjRTe2evDyElfMl/Pjs7cEV0jndFLVv cOmohz/m0Kg9unUlqGjsKUCTv2/jNEgGGx3GxyrhR2q16aOPvnQCPw/0GJoCRTCglH0K QCEfy/3nMjvE9b40fOUpiZuBZwk9aL+4iX+66kII+Chc6AsfMa8ND8FY8J9Uz7PAESxq eN0Lht6xAERAGThPH4k2kw74qqFDBIFptNg1oK+gAKNJ9lG1oMJgEIX/ZQP/PY3Z7PV6 vCMdSXqXznvyoSTSpvdlL6EncVGy7aghkZV4GPs6AP96/mcr6m60gnXrCSy9FwnG0d9Q zRWA== 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=MAzq5ORhZM8Fv/D0QRpoH1JeyawqjMEtSXTJOgm0gk0=; b=utfu3lDvz69NfCL3opiN2zYH7i/JX6bjA/OzNyEAxaX/zwRkM893zdKBgMWstYeCwW ykTS6WJFt0eP7f5dcjz/4qybGXuyqOdkmcBJentdMU7ypR1ykqRbL6EMK3JG15vQ4NBE PdLFkfdpl7/kcLI9RoXkSt1ihGW9K4fv+6DWU4/IubFX7thfpGuKGoNv24olA/qkpKdA 9iDVGX7RZBs6vNQuB11ha471vfTzNCazfmnMbHZac7ngNGOCHYLfx/BpHpFDB/s8heLi 7vtKuSOcaNXeQ0RIABk/eqN1d42aNbOyiuGQMlS5DzzD5doy+RDIeGpTg+pt2+ATJ+JS 1n5g== 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 g9si1377989otq.68.2020.02.13.08.04.31; Thu, 13 Feb 2020 08:04:45 -0800 (PST) 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 S1728744AbgBMQCL (ORCPT + 99 others); Thu, 13 Feb 2020 11:02:11 -0500 Received: from smtprelay0076.hostedemail.com ([216.40.44.76]:38045 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727955AbgBMPYe (ORCPT ); Thu, 13 Feb 2020 10:24:34 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 64D68180AAD53; Thu, 13 Feb 2020 15:24:32 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:800:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3872:4321:4605:5007:6119:7903:10004:10400:11026:11658:11914:12043:12048:12291:12297:12555:12683:12760:13439:14110:14181:14394:14659:14721:14877:21080:21627:21990:30054:30070,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:2,LUA_SUMMARY:none X-HE-Tag: fact83_447fe222a2361 X-Filterd-Recvd-Size: 3345 Received: from XPS-9350.home (unknown [47.151.143.254]) (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA; Thu, 13 Feb 2020 15:24:30 +0000 (UTC) Message-ID: <8b6c1b9031ab9f3cdebada06b8d46467f1492d68.camel@perches.com> Subject: [PATCH] checkpatch: Prefer fallthrough; over fallthrough comments From: Joe Perches To: Rasmus Villemoes , Greg Kroah-Hartman , "Gustavo A. R. Silva" , Andrew Morton Cc: Timur Tabi , Li Yang , Anton Vorontsov , kbuild test robot , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 13 Feb 2020 07:23:13 -0800 In-Reply-To: <6ab68169-dde6-b5ba-0909-fa685bd24aac@rasmusvillemoes.dk> References: <20200213085401.27862-1-linux@rasmusvillemoes.dk> <20200213125659.GB3325929@kroah.com> <6ab68169-dde6-b5ba-0909-fa685bd24aac@rasmusvillemoes.dk> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.34.1-2 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 commit 294f69e662d1 ("compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use") added the pseudo keyword so add a test for it to checkpatch. Warn on a patch or use --strict for files. Signed-off-by: Joe Perches --- scripts/checkpatch.pl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f3b8434..5579d7 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2286,6 +2286,19 @@ sub pos_last_openparen { return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; } +sub get_raw_comment { + my ($line, $rawline) = @_; + my $comment = ''; + + for my $i (0 .. (length($line) - 1)) { + if (substr($line, $i, 1) eq "$;") { + $comment .= substr($rawline, $i, 1); + } + } + + return $comment; +} + sub process { my $filename = shift; @@ -2447,6 +2460,7 @@ sub process { $sline =~ s/$;/ /g; #with comments as spaces my $rawline = $rawlines[$linenr - 1]; + my $raw_comment = get_raw_comment($line, $rawline); # check if it's a mode change, rename or start of a patch if (!$in_commit_log && @@ -6403,6 +6417,28 @@ sub process { } } +# check for /* fallthrough */ like comment, prefer fallthrough; + my @fallthroughs = ( + 'fallthrough', + '@fallthrough@', + 'lint -fallthrough[ \t]*', + 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', + '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?', + 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', + 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', + ); + if ($raw_comment ne '') { + foreach my $ft (@fallthroughs) { + if ($raw_comment =~ /$ft/) { + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}("PREFER_FALLTHROUGH", + "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr); + last; + } + } + } + # check for switch/default statements without a break; if ($perl_version_ok && defined $stat &&