Skip to contentSkip to conversation

checkpatch: Fixing two cases of false positives in checkpatch.pl

PATCH Applied Leonid Bloch 4 participants 13 messages Oct 29, 2015 – Feb 11, 2016 Checkpatch

lore
Share & tools
lore
#0 lore raw

cover checkpatch: Fixing two cases of false positives in checkpatch.pl

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/2 checkpatch: Eliminate false positive in case of comma-space-square bracket

Previously, an error was printed in cases such as:
{ [1] = 5, [2] = 6 }
The space passed OK after a curly brace, but not after a comma. Now, a space before a square bracket is allowed, if a comma comes before it.

---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +3 -1
index b0f6e11..455d94b 100755
@@ -1715,11 +1715,13 @@ sub process {
 #  1. with a type on the left -- int [] a;
 #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
 #  3. inside a curly brace -- = { [0...10] = 5 }
+#  4. after a comma -- [1] = 5, [2] = 6
 		while ($line =~ /(.*?\s)\[/g) {
 			my ($where, $prefix) = ($-[1], $1);
 			if ($prefix !~ /$Type\s+$/ &&
 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
-			    $prefix !~ /{\s+$/) {
+			    $prefix !~ /{\s+$/ &&
+			    $prefix !~ /,\s+$/) {
 				ERROR("space prohibited before open square bracket '['\n" . $herecurr);
 			}
 		}
Signature · 1 line
2.4.3
#2 lore raw

PATCH 2/2 checkpatch: Eliminate false positive in case of space before square bracket in a definition

In reply to Leonid Bloch

Now, macro definition such as "#define abc(x) [x] = y" should pass without an error.

---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index 455d94b..e7d9cce 100755
@@ -1716,11 +1716,13 @@ sub process {
 #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
 #  3. inside a curly brace -- = { [0...10] = 5 }
 #  4. after a comma -- [1] = 5, [2] = 6
+#  5. in a macro definition -- #define abc(x) [x] = y
 		while ($line =~ /(.*?\s)\[/g) {
 			my ($where, $prefix) = ($-[1], $1);
 			if ($prefix !~ /$Type\s+$/ &&
 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
 			    $prefix !~ /{\s+$/ &&
+			    $prefix !~ /\#\s*define[^(]*\([^)]*\)\s+$/ &&
 			    $prefix !~ /,\s+$/) {
 				ERROR("space prohibited before open square bracket '['\n" . $herecurr);
 			}
Signature · 1 line
2.4.3
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] checkpatch: Eliminate false positive in case of space before square bracket in a definition

Quoted 2 lines · Leonid Bloch

Now, macro definition such as "#define abc(x) [x] = y" should pass without an error.

Do we even have macros like that? Without context, it seems like that macro definition is under-parenthesized, and that you wouldn't want to use abc(x) in an arbitrary expression for fear of precedence rules causing nasty surprises.

Quoted 25 lines
---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index 455d94b..e7d9cce 100755
@@ -1716,11 +1716,13 @@ sub process {
 #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
 #  3. inside a curly brace -- = { [0...10] = 5 }
 #  4. after a comma -- [1] = 5, [2] = 6
+#  5. in a macro definition -- #define abc(x) [x] = y
 		while ($line =~ /(.*?\s)\[/g) {
 			my ($where, $prefix) = ($-[1], $1);
 			if ($prefix !~ /$Type\s+$/ &&
 			    ($where != 0 || $prefix !~ /^.\s+$/) &&
 			    $prefix !~ /{\s+$/ &&
+			    $prefix !~ /\#\s*define[^(]*\([^)]*\)\s+$/ &&
 			    $prefix !~ /,\s+$/) {
 				ERROR("space prohibited before open square bracket '['\n" . $herecurr);
 			}
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] checkpatch: Eliminate false positive in case of space before square bracket in a definition

Quoted 9 lines · Eric Blake
Quoted 2 lines · Leonid Bloch

Now, macro definition such as "#define abc(x) [x] = y" should pass without an error.

Do we even have macros like that? Without context, it seems like that macro definition is under-parenthesized, and that you wouldn't want to use abc(x) in an arbitrary expression for fear of precedence rules causing nasty surprises.

Yes, for example, in hw/net/e1000.c, there is:
#define getreg(x) [x] = mac_readreg (l: 1209)
#define putreg(x) [x] = mac_writereg (l: 1230)

This issue came up in the latest patches I've sent to e1000, and in the RFC patches we have sent for e1000e.

Leonid.

Quoted 31 lines
Quoted 16 lines
---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +0 -0
index 455d94b..e7d9cce 100755
@@ -1716,11 +1716,13 @@ sub process {
 #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
 #  3. inside a curly brace -- = { [0...10] = 5 }
 #  4. after a comma -- [1] = 5, [2] = 6

scripts/checkpatch.pl sub process { · line 1728

Quoted 10 lines
scripts/checkpatch.pl +2 -0
+#  5. in a macro definition -- #define abc(x) [x] = y
              while ($line =~ /(.*?\s)\[/g) {
                      my ($where, $prefix) = ($-[1], $1);
                      if ($prefix !~ /$Type\s+$/ &&
                          ($where != 0 || $prefix !~ /^.\s+$/) &&
                          $prefix !~ /{\s+$/ &&
+                         $prefix !~ /\#\s*define[^(]*\([^)]*\)\s+$/ &&
                          $prefix !~ /,\s+$/) {
                              ERROR("space prohibited before open square bracket '['\n" . $herecurr);
                      }

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#5 lore raw
In reply to Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 16 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.4.3

#6 lore raw

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 22 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 16 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.4.3

#7 lore raw

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 31 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 6 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

On Thu, Oct 29, 2015 at 11:48 AM, Leonid Bloch <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual

commits).

Quoted 13 lines
Quoted 13 lines

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.4.3

#8 lore raw

ping

Quoted 42 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 33 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 6 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

On Thu, Oct 29, 2015 at 11:48 AM, Leonid Bloch <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line

This series addresses two cases where errors were printed if

whitespaces

Quoted 1 line
Quoted 1 line

appeared in front of a square bracket in places where there should be

no

Quoted 1 line
Quoted 1 line

problem with such placements (please see messages of individual

commits).

Quoted 13 lines
Quoted 13 lines

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.4.3

#9 lore raw
In reply to Leonid Bloch

Copying Paolo.

Quoted 12 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
#10 lore raw

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 18 lines · Markus Armbruster

Copying Paolo.

Quoted 12 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
#11 lore raw

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 27 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 19 lines · Markus Armbruster

Copying Paolo.

Quoted 13 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
#12 lore raw
Quoted 33 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 27 lines · Leonid Bloch

ping

http://patchwork.ozlabs.org/patch/537763
http://patchwork.ozlabs.org/patch/537762

Quoted 19 lines · Markus Armbruster

Copying Paolo.

Quoted 13 lines · Leonid Bloch

This series addresses two cases where errors were printed if whitespaces appeared in front of a square bracket in places where there should be no problem with such placements (please see messages of individual commits).

Leonid Bloch (2):
checkpatch: Eliminate false positive in case of comma-space-square
bracket
checkpatch: Eliminate false positive in case of space before square
bracket in a definition

 scripts/checkpatch.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Thanks, applied to my queue.

Paolo