mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: checkpatch
Date: Wed, 09 Dec 2020 21:25:37 -0800	[thread overview]
Message-ID: <aea0efa93c17e431205eeb932a73efa7e21598a3.camel@perches.com> (raw)
In-Reply-To: <87zh2mzw3h.fsf@nanos.tec.linutronix.de>

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) =



       reply	other threads:[~2020-12-10  5:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87zh2mzw3h.fsf@nanos.tec.linutronix.de>
2020-12-10  5:25 ` Joe Perches [this message]
2020-12-10  9:34   ` checkpatch David Laight
2020-12-10 13:40     ` checkpatch Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aea0efa93c17e431205eeb932a73efa7e21598a3.camel@perches.com \
    --to=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®