mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Marion & 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: Re: [PATCH] checkpatch: check for missing \n at the end of logging message
Date: Wed, 08 Apr 2020 20:10:23 -0700	[thread overview]
Message-ID: <efb5a518fdc47f0120b94a7e8a95d275c0f4ad43.camel@perches.com> (raw)
In-Reply-To: <4b7e1cf3-6fa7-60af-a1d3-2457339dbe8a@wanadoo.fr>

On Wed, 2020-04-08 at 22:23 +0200, Marion & Christophe JAILLET wrote:
> Le 08/04/2020 à 04:14, Joe Perches a écrit :
> > This works rather better:
> > 
> > Perhaps you could test?
> > ---
> > 
> > v2:
> > 
> > o Avoid pr_cont
> > o Use only last format line if split across multiple lines
> > 
> >   scripts/checkpatch.pl | 22 ++++++++++++++++++++++
> >   1 file changed, 22 insertions(+)
> > 
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index d64c67..f00a6c8 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -5673,6 +5673,28 @@ 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)_/) {
> > +			my $cnt = statement_rawlines($stat);
> > +			my $extracted_string = "";
> > +			for (my $i = 0; $i < $cnt; $i++) {
> > +				next if ($lines[$linenr + $i - 1] !~ /$String\s*[,\)]/);
> > +				$extracted_string = get_quoted_string($lines[$linenr + $i - 1],
> > +								      $rawlines[$linenr + $i - 1]);
> > +				last if ($extracted_string ne "");
> > +			}
> > +			if ($extracted_string ne "" && $extracted_string !~ /\\n"$/) {
> > +				my $herectx = $here . "\n";
> > +				for (my $n = 0; $n < $cnt; $n++) {
> > +					$herectx .=  raw_line($linenr, $n) . "\n";
> > +				}
> > +				WARN("MISSING_FORMAT_NEWLINE",
> > +				     "Possible missing '\\n' at the end of a logging message format string\n" . $herectx);
> > +			}
> > +		}
> > +
> >   # check for logging functions with KERN_<LEVEL>
> >   		if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
> >   		    $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
> > 
> For what I wanted to check and according to the few tests I've made, it 
> looks fine.
> 
> Thank you very much for sharing this much more robust (and working) 
> alternative.
> 
> For what it worth: (i.e. much more tests should be done)
> Tested-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Then I think you really haven't tested it very thoroughly.

For instance:

$ git ls-files -- 'drivers/*.[ch]' | \
  xargs ./scripts/checkpatch.pl -f --quiet --no-summary --types=MISSING_FORMAT_NEWLINE

emits many false positives.

Some types of false positives:

o Many of the formats seem to end in a ':' or a ' '
  maybe those should be excluded
   #86: FILE: drivers/android/binder_alloc_selftest.c:86:
   +	pr_err("free seq: ");

   o Split string formats should be excluded better
     as only the first string fragment is checked:
   #1001: FILE: drivers/ata/pata_octeon_cf.c:1001:
   +	dev_info(&pdev->dev, "version " DRV_VERSION" %d bit%s.\n",
   +		 is_16bit ? 16 : 8,
   +		 cf_port->is_true_ide ? ", True IDE" : "");

   probably a few others, including a desire to check
   if a pr_cont is below the use within a few lines.

   > Maybe, at least a Suggested-By: would be appreciated.

No worries, when it's cooked, it'll have that.

cheers, Joe


  reply	other threads:[~2020-04-09  3:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07 20:49 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 [this message]
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           ` Andy? checkpatch $stat question (was: Re: [PATCH] checkpatch: check for missing \n at the end of logging message) Joe Perches
2020-04-11  7:12         ` [PATCH] checkpatch: check for missing \n at the end of logging message 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=efb5a518fdc47f0120b94a7e8a95d275c0f4ad43.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®