Re: [PATCH v2] checkpatch: Add a warning for log messages that don't end in a new line
From: Joe Perches
Date: Mon Nov 27 2017 - 12:26:16 EST
On Mon, 2017-11-27 at 10:07 -0700, Logan Gunthorpe wrote:
>
> On 27/11/17 02:25 AM, Joe Perches wrote:
> > []
> > diff -u -p a/lib/locking-selftest.c b/lib/locking-selftest.c
> > --- a/lib/locking-selftest.c
> > +++ b/lib/locking-selftest.c
> > @@ -1186,7 +1186,7 @@ static void dotest(void (*testcase_fn)(v
> >
> > static inline void print_testname(const char *testname)
> > {
> > - printk("%33s:", testname);
> > + printk("%33s:\n", testname);
> > }
>
> Coincidentally, the checkpatch script does not hit this false positive.
> This because a pr_cont actually follows in a #define. It doesn't feel
> right but checkpatch does do the correct thing on this one.
>
> > diff -u -p a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -562,7 +562,8 @@ void __dynamic_pr_debug(struct _ddebug *
> > vaf.fmt = fmt;
> > vaf.va = &args;
> >
> > - printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
> > + printk(KERN_DEBUG "%s%pV\n", dynamic_emit_prefix(descriptor, buf),
> > + &vaf);
> >
> > va_end(args);
> > }
>
> This is a valid false positive that I also missed. However, it can
> actually be very easily ignored by checking if the format string ends in
> %pV. There were about 100 cases in my results that match this.
No, it can't be done that way.
$ git grep '%pV\\n"' | wc -l
56
$ git grep '%pV"' | wc -l
146
AFAIK: all of the above are correct as-is.