Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1259019 > unrolled thread

[PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives

Started byVladimir Zapolskiy <vz@mleia.com>
First post2015-10-29 22:40 +0100
Last post2015-10-30 01:00 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives Vladimir Zapolskiy <vz@mleia.com> - 2015-10-29 22:40 +0100
    Re: [PATCH] checkpatch: fix a number of COMPLEX_MACRO false  positives Joe Perches <joe@perches.com> - 2015-10-29 23:50 +0100
      Re: [PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives Vladimir Zapolskiy <vz@mleia.com> - 2015-10-30 01:00 +0100

#1259019 — [PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives

FromVladimir Zapolskiy <vz@mleia.com>
Date2015-10-29 22:40 +0100
Subject[PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives
Message-ID<qp35p-5yq-19@gated-at.bofh.it>
A simple search over the kernel souce displays a number of correctly
defined multiline macro, which generally are used as an array element
initializer:

% find ../linux -type f | xargs grep -B1 -H '^[:space]*\[.*\\$'

However checkpatch.pl unexpectedly complains about all these macro
definitions:

% ./scripts/checkpatch.pl --types COMPLEX_MACRO -f include/linux/perf/arm_pmu.h

ERROR: Macros with complex values should be enclosed in parentheses
+#define PERF_MAP_ALL_UNSUPPORTED					\
+	 [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED

The change intends to fix this type of false positives by flattening
only array members and skipping array element designators.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f2a1131..3882893 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4526,7 +4526,7 @@ sub process {
 			# Flatten any parentheses and braces
 			while ($dstat =~ s/\([^\(\)]*\)/1/ ||
 			       $dstat =~ s/\{[^\{\}]*\}/1/ ||
-			       $dstat =~ s/\[[^\[\]]*\]/1/)
+			       $dstat =~ s/.\[[^\[\]]*\]/1/)
 			{
 			}
 
@@ -4546,7 +4546,8 @@ sub process {
 				union|
 				struct|
 				\.$Ident\s*=\s*|
-				^\"|\"$
+				^\"|\"$|
+				^\[
 			}x;
 			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
 			if ($dstat ne '' &&
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1259065 — Re: [PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives

FromJoe Perches <joe@perches.com>
Date2015-10-29 23:50 +0100
SubjectRe: [PATCH] checkpatch: fix a number of COMPLEX_MACRO false positives
Message-ID<qp4b7-6cI-7@gated-at.bofh.it>
In reply to#1259019
On Thu, 2015-10-29 at 23:36 +0200, Vladimir Zapolskiy wrote:
> A simple search over the kernel souce displays a number of correctly
> defined multiline macro, which generally are used as an array element
> initializer:
> 
> % find ../linux -type f | xargs grep -B1 -H '^[:space]*\[.*\\$'
> 
> However checkpatch.pl unexpectedly complains about all these macro
> definitions:
> 
> % ./scripts/checkpatch.pl --types COMPLEX_MACRO -f include/linux/perf/arm_pmu.h
> 
> ERROR: Macros with complex values should be enclosed in parentheses
> +#define PERF_MAP_ALL_UNSUPPORTED					\
> +	 [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
> 
> The change intends to fix this type of false positives by flattening
> only array members and skipping array element designators.
> 
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
> ---
>  scripts/checkpatch.pl | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index f2a1131..3882893 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4526,7 +4526,7 @@ sub process {
>  			# Flatten any parentheses and braces
>  			while ($dstat =~ s/\([^\(\)]*\)/1/ ||
>  			       $dstat =~ s/\{[^\{\}]*\}/1/ ||
> -			       $dstat =~ s/\[[^\[\]]*\]/1/)
> +			       $dstat =~ s/.\[[^\[\]]*\]/1/)

Perhaps the . before the [ might be a bit broad.

I'm not sure there's a great way to handle this.

Andy?

>  			{
>  			}
>  
> @@ -4546,7 +4546,8 @@ sub process {
>  				union|
>  				struct|
>  				\.$Ident\s*=\s*|
> -				^\"|\"$
> +				^\"|\"$|
> +				^\[
>  			}x;
>  			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
>  			if ($dstat ne '' &&



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1259129

FromVladimir Zapolskiy <vz@mleia.com>
Date2015-10-30 01:00 +0100
Message-ID<qp5gS-6PF-5@gated-at.bofh.it>
In reply to#1259065
On 30.10.2015 00:46, Joe Perches wrote:
> On Thu, 2015-10-29 at 23:36 +0200, Vladimir Zapolskiy wrote:
>> A simple search over the kernel souce displays a number of correctly
>> defined multiline macro, which generally are used as an array element
>> initializer:
>>
>> % find ../linux -type f | xargs grep -B1 -H '^[:space]*\[.*\\$'
>>
>> However checkpatch.pl unexpectedly complains about all these macro
>> definitions:
>>
>> % ./scripts/checkpatch.pl --types COMPLEX_MACRO -f include/linux/perf/arm_pmu.h
>>
>> ERROR: Macros with complex values should be enclosed in parentheses
>> +#define PERF_MAP_ALL_UNSUPPORTED					\
>> +	 [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
>>
>> The change intends to fix this type of false positives by flattening
>> only array members and skipping array element designators.
>>
>> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
>> ---
>>  scripts/checkpatch.pl | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index f2a1131..3882893 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -4526,7 +4526,7 @@ sub process {
>>  			# Flatten any parentheses and braces
>>  			while ($dstat =~ s/\([^\(\)]*\)/1/ ||
>>  			       $dstat =~ s/\{[^\{\}]*\}/1/ ||
>> -			       $dstat =~ s/\[[^\[\]]*\]/1/)
>> +			       $dstat =~ s/.\[[^\[\]]*\]/1/)
> 
> Perhaps the . before the [ might be a bit broad.

At this point preceding spaces and parentheses are removed, probably any
alphanumeric symbol should fit here.

OTOH I believe in correct C code here before \[ symbol you may find only
an alphanumeric symbol or ^, so I don't expect any false negatives, if .
is used above.

> I'm not sure there's a great way to handle this.
> 
> Andy?
> 
>>  			{
>>  			}
>>  
>> @@ -4546,7 +4546,8 @@ sub process {
>>  				union|
>>  				struct|
>>  				\.$Ident\s*=\s*|
>> -				^\"|\"$
>> +				^\"|\"$|
>> +				^\[
>>  			}x;
>>  			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
>>  			if ($dstat ne '' &&
> 
> 
> 

--
With best wishes,
Vladimir
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web