diff mbox series

[ovs-dev] checkpatch: Ignore macro definitions of FOR_EACH

Message ID f7to8nral2d.fsf_-_@dhcp-25.97.bos.redhat.com
State Changes Requested
Headers show
Series [ovs-dev] checkpatch: Ignore macro definitions of FOR_EACH | expand

Commit Message

Aaron Conole Aug. 3, 2020, 1:57 p.m. UTC
When defining a FOR_EACH macro, checkpatch freaks out and generates a
control block whitespace error.  Create an exception so that it doesn't
generate errors for this case.

Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2020-August/373509.html
Reported-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
---

Comments

Aaron Conole Aug. 25, 2020, 3:42 p.m. UTC | #1
Aaron Conole <aconole@redhat.com> writes:

> When defining a FOR_EACH macro, checkpatch freaks out and generates a
> control block whitespace error.  Create an exception so that it doesn't
> generate errors for this case.
>
> Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2020-August/373509.html
> Reported-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---

Ping.  Any comments?

> diff --git a/tests/checkpatch.at b/tests/checkpatch.at
> index 6c73947722..042090a0f6 100755
> --- a/tests/checkpatch.at
> +++ b/tests/checkpatch.at
> @@ -284,6 +284,11 @@ try_checkpatch \
>      +     for (init; condition; increment) { \\
>      "
>  
> +try_checkpatch \
> +   "COMMON_PATCH_HEADER
> +    +#define SOME_FOR_EACH(a, b, c) /* Foo. */
> +   "
> +
>  AT_CLEANUP
>  
>  
> diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
> index 7f1d21a40e..abe76ff3ba 100755
> --- a/utilities/checkpatch.py
> +++ b/utilities/checkpatch.py
> @@ -156,6 +156,8 @@ __regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
>  __regex_leading_with_spaces = re.compile(r'^ +[\S]+')
>  __regex_trailing_whitespace = re.compile(r'[^\S]+$')
>  __regex_single_line_feed = re.compile(r'^\f$')
> +__regex_hash_define_for_each = re.compile(
> +    r'#define [_A-Z]+FOR_*EACH[_A-Z0-9]*\(')
>  __regex_for_if_missing_whitespace = re.compile(r' +(%s)[\(]'
>                                                 % __parenthesized_constructs)
>  __regex_for_if_too_much_whitespace = re.compile(r' +(%s)  +[\(]'
> @@ -245,6 +247,10 @@ def if_and_for_whitespace_checks(line):
>      """
>      if skip_block_whitespace_check:
>          return True
> +
> +    if (__regex_hash_define_for_each.search(line) is not None):
> +        return True
> +
>      if (__regex_for_if_missing_whitespace.search(line) is not None or
>              __regex_for_if_too_much_whitespace.search(line) is not None or
>              __regex_for_if_parens_whitespace.search(line)):
> ---
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Ilya Maximets Aug. 26, 2020, 12:03 p.m. UTC | #2
On 8/25/20 5:42 PM, Aaron Conole wrote:
> Aaron Conole <aconole@redhat.com> writes:
> 
>> When defining a FOR_EACH macro, checkpatch freaks out and generates a
>> control block whitespace error.  Create an exception so that it doesn't
>> generate errors for this case.
>>
>> Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2020-August/373509.html
>> Reported-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>> ---
> 
> Ping.  Any comments?
> 
>> diff --git a/tests/checkpatch.at b/tests/checkpatch.at
>> index 6c73947722..042090a0f6 100755
>> --- a/tests/checkpatch.at
>> +++ b/tests/checkpatch.at
>> @@ -284,6 +284,11 @@ try_checkpatch \
>>      +     for (init; condition; increment) { \\
>>      "
>>  
>> +try_checkpatch \
>> +   "COMMON_PATCH_HEADER
>> +    +#define SOME_FOR_EACH(a, b, c) /* Foo. */
>> +   "
>> +
>>  AT_CLEANUP
>>  
>>  
>> diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
>> index 7f1d21a40e..abe76ff3ba 100755
>> --- a/utilities/checkpatch.py
>> +++ b/utilities/checkpatch.py
>> @@ -156,6 +156,8 @@ __regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
>>  __regex_leading_with_spaces = re.compile(r'^ +[\S]+')
>>  __regex_trailing_whitespace = re.compile(r'[^\S]+$')
>>  __regex_single_line_feed = re.compile(r'^\f$')
>> +__regex_hash_define_for_each = re.compile(
>> +    r'#define [_A-Z]+FOR_*EACH[_A-Z0-9]*\(')
>>  __regex_for_if_missing_whitespace = re.compile(r' +(%s)[\(]'
>>                                                 % __parenthesized_constructs)
>>  __regex_for_if_too_much_whitespace = re.compile(r' +(%s)  +[\(]'
>> @@ -245,6 +247,10 @@ def if_and_for_whitespace_checks(line):
>>      """
>>      if skip_block_whitespace_check:
>>          return True
>> +
>> +    if (__regex_hash_define_for_each.search(line) is not None):

Maybe this 'if' should return only if __regex_for_if_missing_whitespace ?
i.e. if mising_whitespace and not define_for_each: return False;

'missing_whitespace' check could be removed from the next 'if' condition
in this case.

>> +        return True
>> +
>>      if (__regex_for_if_missing_whitespace.search(line) is not None or
>>              __regex_for_if_too_much_whitespace.search(line) is not None or
>>              __regex_for_if_parens_whitespace.search(line)):
>> ---
>>
>> _______________________________________________
>> dev mailing list
>> dev@openvswitch.org
>> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox series

Patch

diff --git a/tests/checkpatch.at b/tests/checkpatch.at
index 6c73947722..042090a0f6 100755
--- a/tests/checkpatch.at
+++ b/tests/checkpatch.at
@@ -284,6 +284,11 @@  try_checkpatch \
     +     for (init; condition; increment) { \\
     "
 
+try_checkpatch \
+   "COMMON_PATCH_HEADER
+    +#define SOME_FOR_EACH(a, b, c) /* Foo. */
+   "
+
 AT_CLEANUP
 
 
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 7f1d21a40e..abe76ff3ba 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -156,6 +156,8 @@  __regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
 __regex_leading_with_spaces = re.compile(r'^ +[\S]+')
 __regex_trailing_whitespace = re.compile(r'[^\S]+$')
 __regex_single_line_feed = re.compile(r'^\f$')
+__regex_hash_define_for_each = re.compile(
+    r'#define [_A-Z]+FOR_*EACH[_A-Z0-9]*\(')
 __regex_for_if_missing_whitespace = re.compile(r' +(%s)[\(]'
                                                % __parenthesized_constructs)
 __regex_for_if_too_much_whitespace = re.compile(r' +(%s)  +[\(]'
@@ -245,6 +247,10 @@  def if_and_for_whitespace_checks(line):
     """
     if skip_block_whitespace_check:
         return True
+
+    if (__regex_hash_define_for_each.search(line) is not None):
+        return True
+
     if (__regex_for_if_missing_whitespace.search(line) is not None or
             __regex_for_if_too_much_whitespace.search(line) is not None or
             __regex_for_if_parens_whitespace.search(line)):