From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32A3AC4361B for ; Thu, 10 Dec 2020 05:26:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4D7923B98 for ; Thu, 10 Dec 2020 05:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727336AbgLJF01 (ORCPT ); Thu, 10 Dec 2020 00:26:27 -0500 Received: from smtprelay0220.hostedemail.com ([216.40.44.220]:42478 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726313AbgLJF0W (ORCPT ); Thu, 10 Dec 2020 00:26:22 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay08.hostedemail.com (Postfix) with ESMTP id CDDFC182CED34; Thu, 10 Dec 2020 05:25:40 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: page55_1912e53273f5 X-Filterd-Recvd-Size: 2444 Received: from XPS-9350.home (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf15.hostedemail.com (Postfix) with ESMTPA; Thu, 10 Dec 2020 05:25:40 +0000 (UTC) Message-ID: Subject: Re: checkpatch From: Joe Perches To: Thomas Gleixner Cc: LKML Date: Wed, 09 Dec 2020 21:25:37 -0800 In-Reply-To: <87zh2mzw3h.fsf@nanos.tec.linutronix.de> References: <87zh2mzw3h.fsf@nanos.tec.linutronix.de> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-12-09 at 19:13 +0100, Thomas Gleixner wrote: > Joe, Hi Thomas. > the below made it through my filters for some reason so I actually > looked and immediately wondered why checkpatch.pl did not identify this > as pure garbage. > >  Original mail is here: lore.kernel.org/r/69cb540a-09d5-4956-b062-071ccded7090@web.de > > Can you have a look please? Adding brackets in the middle of the code > for absolutely no reason is wrong to begin with and then not indenting > the enclosed code makes it even worse. Well, maybe something like this, but there are probably some drawbacks with initializations. --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7b086d1cd6c2..057be2cfe118 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4047,6 +4047,25 @@ sub process { } } +# Check open brace and any possible statement indentation + if (defined($stat) && + $stat =~ /^\+([ \t]+)\{[ \t]*\n/) { + if (substr($stat, pos($stat), length($1)+1) !~ /^$1\s/) { + my $cnt = statement_rawlines($stat); + my $herectx = get_stat_here($linenr, $cnt, $here); + my @array = split(/\n/, $herectx); + $cnt = 0; + $herectx = ""; + foreach my $aline (@array) { + $herectx .= $aline . "\n"; + $cnt++ if ($aline =~ /^\+/); + last if ($cnt >= 2); + } + WARN("OPEN_BRACE", + "A line with only an open brace should start an indented block\n" . $herectx); + } + } + # Check relative indent for conditionals and blocks. if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { ($stat, $cond, $line_nr_next, $remain_next, $off_next) =