[Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions

Philippe Mathieu-Daudé posted 46 patches 7 years, 7 months ago
Only 43 patches received!
[Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions
Posted by Philippe Mathieu-Daudé 7 years, 7 months ago
Do not match the IEC binary prefix as camelcase typedefs.

This fixes:

    ERROR: "foo * bar" should be "foo *bar"
    #310: FILE: hw/ppc/ppc440_uc.c:564:
    +        size = 8 * MiB * sh;
    total: 1 errors, 0 warnings, 433 lines checked

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3d8c2cdfc..223681bfd0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -242,6 +242,7 @@ our $UTF8	= qr{
 # There are still some false positives, but this catches most
 # common cases.
 our $typeTypedefs = qr{(?x:
+        (?![KMGTPE]iB)                      # IEC binary prefix (do not match)
         [A-Z][A-Z\d_]*[a-z][A-Za-z\d_]*     # camelcase
         | [A-Z][A-Z\d_]*AIOCB               # all uppercase
         | [A-Z][A-Z\d_]*CPU                 # all uppercase
-- 
2.18.0


Re: [Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions
Posted by Eric Blake 7 years, 7 months ago
On 06/25/2018 07:41 AM, Philippe Mathieu-Daudé wrote:
> Do not match the IEC binary prefix as camelcase typedefs.
> 
> This fixes:
> 
>      ERROR: "foo * bar" should be "foo *bar"
>      #310: FILE: hw/ppc/ppc440_uc.c:564:
>      +        size = 8 * MiB * sh;
>      total: 1 errors, 0 warnings, 433 lines checked
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   scripts/checkpatch.pl | 1 +
>   1 file changed, 1 insertion(+)

Warning - my perl regex-fu is weak; but I'll give this a shot.

> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e3d8c2cdfc..223681bfd0 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -242,6 +242,7 @@ our $UTF8	= qr{
>   # There are still some false positives, but this catches most
>   # common cases.
>   our $typeTypedefs = qr{(?x:
> +        (?![KMGTPE]iB)                      # IEC binary prefix (do not match)

I had to (re-)read 'perldoc perlretut', but found what I was looking 
for.  You are adding a zero-length negated lookahead assertion that 
anything matching the pattern [KMGTPE]iB is not matched to the rest of 
the regex.

>           [A-Z][A-Z\d_]*[a-z][A-Za-z\d_]*     # camelcase
>           | [A-Z][A-Z\d_]*AIOCB               # all uppercase
>           | [A-Z][A-Z\d_]*CPU                 # all uppercase

and the rest of this regex is picking out any sequence that the code 
should treat as a typedef.  Ergo, with your negative lookahead, we are 
no longer treating the numeric mixed-case constants as typedefs, and the 
rest of the script that warns on formatting issues where a typedef 
appears to be used with a '*' for creating a pointer no longer trigger.

Since that's enough to shut up the false positives you were seeing, then 
it looks right to me.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions
Posted by Joe Perches 7 years, 7 months ago
On Fri, 2018-06-29 at 15:41 -0500, Eric Blake wrote:
> On 06/25/2018 07:41 AM, Philippe Mathieu-Daudé wrote:
> > Do not match the IEC binary prefix as camelcase typedefs.
> > 
> > This fixes:
> > 
> >      ERROR: "foo * bar" should be "foo *bar"
> >      #310: FILE: hw/ppc/ppc440_uc.c:564:
> >      +        size = 8 * MiB * sh;
> >      total: 1 errors, 0 warnings, 433 lines checked

Does the linux kernel use these?
I don't believe so.

> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> > @@ -242,6 +242,7 @@ our $UTF8	= qr{
> >   # There are still some false positives, but this catches most
> >   # common cases.
> >   our $typeTypedefs = qr{(?x:
> > +        (?![KMGTPE]iB)                      # IEC binary prefix (do not match)

Re: [Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions
Posted by Paolo Bonzini 7 years, 7 months ago
On 29/06/2018 23:46, Joe Perches wrote:
>>>      ERROR: "foo * bar" should be "foo *bar"
>>>      #310: FILE: hw/ppc/ppc440_uc.c:564:
>>>      +        size = 8 * MiB * sh;
>>>      total: 1 errors, 0 warnings, 433 lines checked
> Does the linux kernel use these?
> I don't believe so.
> 

No, I'm not sure why you were CCed. :)

Paolo

Re: [Qemu-devel] [PATCH v5 04/46] checkpatch: Recognize IEC binary prefix definitions
Posted by Joe Perches 7 years, 7 months ago
On Mon, 2018-07-02 at 14:37 +0200, Paolo Bonzini wrote:
> On 29/06/2018 23:46, Joe Perches wrote:
> > > >      ERROR: "foo * bar" should be "foo *bar"
> > > >      #310: FILE: hw/ppc/ppc440_uc.c:564:
> > > >      +        size = 8 * MiB * sh;
> > > >      total: 1 errors, 0 warnings, 433 lines checked
> > 
> > Does the linux kernel use these?
> > I don't believe so.
> > 
> No, I'm not sure why you were CCed. :)

Me neither but I am the kernel MAINTAINERS file as
checkpatch maintainer.

My guess is some MAINTAINERS file has me in it or qemu
uses git history for unmaintained files and qemu pulls
in the kernel checkpatch changes.