From: Joe Perches <joe@perches.com>
To: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: Re: [PATCH RFC] checkpatch: fix multi-statement macro checks
Date: Thu, 01 Oct 2020 07:38:12 -0700 [thread overview]
Message-ID: <361bda20762efce0e374bd2ba7c82d1c64628a67.camel@perches.com> (raw)
In-Reply-To: <CABJPP5AM01voDwARL4G0vMhFw4hMY+=dEQ7=obiKPzNtunyb7Q@mail.gmail.com>
On Thu, 2020-10-01 at 19:44 +0530, Dwaipayan Ray wrote:
> On Thu, Oct 1, 2020 at 7:12 PM Joe Perches <joe@perches.com> wrote:
> > On Thu, 2020-10-01 at 18:57 +0530, Dwaipayan Ray wrote:
> > > On Thu, Oct 1, 2020 at 6:47 PM Joe Perches <joe@perches.com> wrote:
> > > > On Thu, 2020-10-01 at 16:03 +0530, Dwaipayan Ray wrote:
> > > > > Checkpatch.pl doesn't have a check for excluding while (...) {...}
> > > > > blocks from MULTISTATEMENT_MACRO_USE_DO_WHILE error.
> > > > >
> > > > > For example, running checkpatch.pl on the file mm/access.c in the
> > > > > kernel generates the following error:
> > > > >
> > > > > ERROR: Macros with complex values should be enclosed in parentheses
> > > > > +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label) \
> > > > > + while (len >= sizeof(type)) { \
> > > > > + __get_kernel_nofault(dst, src, type, err_label); \
> > > > > + dst += sizeof(type); \
> > > > > + src += sizeof(type); \
> > > > > + len -= sizeof(type); \
> > > > > + }
> > > > >
> > > > > The error is misleading for this case. Enclosing it in parantheses
> > > > > doesn't make any sense.
> > > >
> > > > OK
> > > >
> > > > > Checkpatch already has an exception list for such common macro types.
> > > > > Added a new exception for while (...) {...} style blocks to the same.
> > > > > This effectively fixed the wrong error message.
> > > > []
> > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > > []
> > > > > @@ -5342,6 +5342,7 @@ sub process {
> > > > > $dstat !~ /^\.$Ident\s*=/ && # .foo =
> > > > > $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
> > > > > $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
> > > > > + $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
> >
> > Note the \s*
> > ^
> >
> > > > Did you try to output $dstat for some matching cases?
> > > > What was the $dstat value for the cases you tried?
> > > >
> > > >
> > > Hi,
> > > I did check $dstat values.
> > >
> > > For example on file mm/maccess.c, there were two such macros:
> > >
> > > Case 1:
> > >
> > > $ctx:
> > > +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label) \
> > > + while (len >= sizeof(type)) { \
> > > + __get_kernel_nofault(dst, src, type, err_label); \
> > > + dst += sizeof(type); \
> > > + src += sizeof(type); \
> > > + len -= sizeof(type); \
> > > + }
> > >
> > > $dstat:
> > > while 1 1
> >
> > And perhaps this test should use \s+ instead.
> > What is $dstat with a #define like:
> >
> > #define foo(bar,baz)while(bar){bar--;baz++;}
> >
> > (no spaces anywhere bot the required one after define
> >
>
> In this case, $dstat is: while11
>
> So, if \s+ is used, it won't match with this. I ran checkpatch
> on it and some other condition seems to match, so it is
> excluded from the error.
>
> However, if the macro is like:
>
> #define foo(bar,baz)while(bar) {bar--;baz++;}
> (one space after condition)
>
> $dstat is: while1 1
> (space after first 1)
> and the same error is again emitted.
>
> So I think \s* works better since there can be
> 0 or more whitespaces between them.
All I'm trying to point out to you is that $Constant\s*$Constant
isn't a proper test as the first $Constant will pull the test
entire sequence of digits and the second $Constant will not be
met.
It may take some conversion of the collapsing of the dstat
block to work appropriately
# Flatten any parentheses and braces
while ($dstat =~ s/\([^\(\)]*\)/1/ ||
$dstat =~ s/\{[^\{\}]*\}/1/ ||
$dstat =~ s/.\[[^\[\]]*\]/1/)
{
}
Maybe the /1/ should be / 1 / but I didn't look to see what
happens to the exclusion tests below that.
next prev parent reply other threads:[~2020-10-01 14:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 10:33 Dwaipayan Ray
2020-10-01 11:12 ` Lukas Bulwahn
2020-10-01 13:17 ` Joe Perches
2020-10-01 13:27 ` Dwaipayan Ray
2020-10-01 13:42 ` Joe Perches
2020-10-01 14:14 ` Dwaipayan Ray
2020-10-01 14:38 ` Joe Perches [this message]
2020-10-01 15:26 ` Joe Perches
2020-10-01 15:36 ` Dwaipayan Ray
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=361bda20762efce0e374bd2ba7c82d1c64628a67.camel@perches.com \
--to=joe@perches.com \
--cc=dwaipayanray1@gmail.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
/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®