mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	apw@canonical.com, Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Andy? checkpatch $stat question (was: Re: [PATCH] checkpatch: check for missing \n at the end of logging message)
Date: Sat, 11 Apr 2020 03:10:36 -0700	[thread overview]
Message-ID: <6403ebf6b928d94268e00d52371c6aec912c3335.camel@perches.com> (raw)
In-Reply-To: <215f2a43-6677-04cd-f376-bd7cd051b626@wanadoo.fr>

Andy Whitcroft:  checkpatch internals question for you below:

On Sat, 2020-04-11 at 08:48 +0200, Christophe JAILLET wrote:
> Le 10/04/2020 à 21:53, Joe Perches a écrit :
> > On Fri, 2020-04-10 at 12:46 -0700, Joe Perches wrote:
> > > On Fri, 2020-04-10 at 19:35 +0200, Christophe JAILLET wrote:
> > > > Le 08/04/2020 à 04:14, Joe Perches a écrit :
> > > > > This works rather better:
> > > > > Perhaps you could test?
> > > []
> > > > I'm looking at some modification done in the last month that could have
> > > > been spotted by the above script.
> > > > 
> > > >       ./scripts/checkpatch.pl -f drivers/usb/phy/phy-jz4770.c
> > > > 
> > > > correctly spots the 3 first cases, but the 3 last (line 202, 210 and
> > > > 217) are missed.
> > > > I don't understand why.
> > > It has to do with checkpatch's single statement parsing.
> > > 
> > > This case:
> > > 
> > > 	if (foo)
> > > 		dev_warn(...);
> > > 
> > > is parsed as a single statement but
> > > 
> > > 	if (foo) {
> > > 		dev_warn(...);
> > > 	};
> > > 
> > > is parsed as multiple statements so for the
> > > second case
> > > 
> > > 		dev_warn(...);
> > > 
> > > is analyzed as a separate statement.
> > > 
> > > The regex match for this missing newline test expects
> > > that each printk is a separate statement so the first
> > > case doesn't match.
> > > 
> > > Clearly the regex can be improved here.
> > So on top of the original patch:
> > ---
> >   scripts/checkpatch.pl | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index f00a6c8..54eaa7 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -5675,8 +5675,8 @@ sub process {
> >   
> >   # check for possible missing newlines at the end of common logging functions
> >   		if (defined($stat) &&
> > -		    $stat =~ /^\+\s*($logFunctions)\s*\((?:\s*$FuncArg\s*,\s*){0,3}\s*$String/ &&
> > -		    $1 !~ /_cont$/ && $1 =~ /^(?:pr|dev|netdev|netif|wiphy)_/) {
> > +		    $stat =~ /^\+\s*(?:if\s*$balanced_parens\s*)?($logFunctions)\s*\((?:\s*$FuncArg\s*,\s*){0,3}\s*$String/ &&
> > +		    $2 !~ /_cont$/ && $2 =~ /^(?:pr|dev|netdev|netif|wiphy)_/) {
> >   			my $cnt = statement_rawlines($stat);
> >   			my $extracted_string = "";
> >   			for (my $i = 0; $i < $cnt; $i++) {
> 
> Hi Joe,
> 
> This fixes the use case for  drivers/usb/phy/phy-jz4770.c
> 
>      ./scripts/checkpatch.pl -f drivers/usb/gadget/udc/tegra-xudc.c
> 
> is missing line 691.

Turns out checkpatch also considers a close brace
followed by another statement block a single statement
so that test could be:

		    $stat =~ /^\+\s*\}?\s*(?:if\s*$balanced_parens\s*)?($logFunctions)\s*\((?:\s*$FuncArg\s*,\s*){0,3}\s*$String/ &&
		    $2 !~ /_cont$/ && $2 =~ /^(?:pr|dev|netdev|netif|wiphy)_/) {

But that seems odd and I wonder if Andy agrees
so I have a question for Andy about the use of
ctx_statement_block and its implementation.

It seems that $suppress_statement should be updated
when the cond return value does not start with { so
that code like

struct foo *
function(
	 int arg1,
	 long arg2,
	 struct bar *baz)
{
	[implementation...]
}

allows skipping the creation of a new $stat for each
line of the function arguments.  Instead there would
be just 2 $stat blocks created, one for the function
with its args and implementation, another for just
the implementation with braces.

Perhaps this is proper, but perhaps the $line_nr_next
return value should be updated in ctx_statement_block
instead.

Also a $stat that starts with a close brace is odd
and probably not good.

Thoughts?

---
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 54eaa7..8ef95b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3558,7 +3558,10 @@ sub process {
 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
 				ctx_statement_block($linenr, $realcnt, 0);
 			$stat =~ s/\n./\n /g;
-			$cond =~ s/\n./\n /g;
+			my $condcnt = $cond =~ s/\n./\n /g;
+			if ($cond !~ /^.\s*\}/) {
+				$suppress_statement = $linenr + $condcnt;
+			}
 
 #print "linenr<$linenr> <$stat>\n";
 			# If this statement has no statement boundaries within


  parent reply	other threads:[~2020-04-11 10:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07 20:49 [PATCH] checkpatch: check for missing \n at the end of logging message Christophe JAILLET
2020-04-08  0:33 ` Joe Perches
2020-04-08 20:19   ` Marion & Christophe JAILLET
2020-04-08  2:14 ` Joe Perches
2020-04-08 20:23   ` Marion & Christophe JAILLET
2020-04-09  3:10     ` Joe Perches
2020-04-09  7:24       ` Christophe JAILLET
2020-04-09  7:24         ` Christophe JAILLET
2020-04-09 15:29         ` Joe Perches
2020-04-09 17:34           ` Christophe JAILLET
2020-04-09 17:34             ` Christophe JAILLET
2020-04-09 17:50             ` Joe Perches
2020-04-09 18:52               ` Christophe JAILLET
2020-04-09 18:52                 ` Christophe JAILLET
2020-04-09 21:40                 ` Joe Perches
2020-04-09 10:40       ` Dan Carpenter
2020-04-10 17:35   ` Christophe JAILLET
2020-04-10 19:46     ` Joe Perches
2020-04-10 19:53       ` Joe Perches
2020-04-11  6:48         ` Christophe JAILLET
2020-04-11  6:48           ` Christophe JAILLET
2020-04-11 10:10           ` Joe Perches [this message]
2020-04-11  7:12         ` Christophe JAILLET
2020-04-11  7:12           ` Christophe JAILLET
2020-04-11  7:13           ` Marion & Christophe JAILLET
2020-04-11 10:17           ` Joe Perches
2020-04-11 10:27             ` Christophe JAILLET
2020-04-11 10:27               ` Christophe JAILLET
2020-04-10 19:34 ` 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=6403ebf6b928d94268e00d52371c6aec912c3335.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®