[ovs-dev] checkpatch: fix pointer declaration

Submitted by Aaron Conole on April 19, 2017, 9:42 p.m.

Details

Message ID 20170419214258.17470-1-aconole@redhat.com
State Superseded
Headers show

Commit Message

Aaron Conole April 19, 2017, 9:42 p.m.
Lance pointed to a problem where scripts were incorrectly being flagged as
pointer spacing warnings.  As an example, the text:

  --u*|-u)

would flag the warning.

Since the type name should always have a space in front of it, change the
regex to require some spacing.  Additionally, ** is a common notation in
comments to mean 'raise to the power of', so ensure that it is not
accidentally flagged as well by adding a not-group populated with *.

Reported-by: Lance Richardson <lrichard@redhat.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 utilities/checkpatch.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ben Pfaff April 19, 2017, 9:52 p.m.
On Wed, Apr 19, 2017 at 05:42:58PM -0400, Aaron Conole wrote:
> Lance pointed to a problem where scripts were incorrectly being flagged as
> pointer spacing warnings.  As an example, the text:
> 
>   --u*|-u)
> 
> would flag the warning.
> 
> Since the type name should always have a space in front of it, change the
> regex to require some spacing.  Additionally, ** is a common notation in
> comments to mean 'raise to the power of', so ensure that it is not
> accidentally flagged as well by adding a not-group populated with *.
> 
> Reported-by: Lance Richardson <lrichard@redhat.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>

Should checkpatch limit C code warnings to C source files and header
files?
Aaron Conole April 20, 2017, 12:30 p.m.
Ben Pfaff <blp@ovn.org> writes:

> On Wed, Apr 19, 2017 at 05:42:58PM -0400, Aaron Conole wrote:
>> Lance pointed to a problem where scripts were incorrectly being flagged as
>> pointer spacing warnings.  As an example, the text:
>> 
>>   --u*|-u)
>> 
>> would flag the warning.
>> 
>> Since the type name should always have a space in front of it, change the
>> regex to require some spacing.  Additionally, ** is a common notation in
>> comments to mean 'raise to the power of', so ensure that it is not
>> accidentally flagged as well by adding a not-group populated with *.
>> 
>> Reported-by: Lance Richardson <lrichard@redhat.com>
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>
> Should checkpatch limit C code warnings to C source files and header
> files?

That's a good suggestion.  I'll cook up a patch to whitelist the files
that are definitely C-code: .c, .h, .c.in, .h.in as suffixes.

You can hold off on applying this if you want to wait for that change as
well - just let me know and I'll submit a series.

Thanks,
-Aaron

Patch hide | download patch | download mbox

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 638ac97..31cbce2 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -68,7 +68,8 @@  __regex_is_for_if_single_line_bracket = \
     re.compile(r'^ +(if|for|while) \(.*\)')
 __regex_ends_with_bracket = \
     re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')
-__regex_ptr_declaration_missing_whitespace = re.compile(r'[a-zA-Z0-9]\*')
+__regex_ptr_declaration_missing_whitespace = \
+    re.compile(r'\s[a-zA-Z0-9_]+\*[^*]')
 
 skip_leading_whitespace_check = False
 skip_trailing_whitespace_check = False