checkpatch: Allow spaces before the ':' of a bitfield
A message that is not in the archive (sent off-list or not yet received): 20131013121635.GA29395@nandinih-Inspiron-5521
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 checkpatch: Allow spaces before the ':' of a bitfield
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
---
Nandini and Greg observed this issue as part of checkpatch warnings on a staging driver (octeon-usb), and both agreed that checkpatch should not issue this warning; patching accordingly.
scripts/checkpatch.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +14 -2
@@ -2934,8 +2934,7 @@ sub process { # No spaces for: # -> - # : when part of a bitfield - } elsif ($op eq '->' || $opv eq ':B') { + } elsif ($op eq '->') { if ($ctx =~ /Wx.|.xW/) { if (ERROR("SPACING", "spaces prohibited around that '$op' $at\n" . $hereptr)) {
@@ -2947,6 +2946,19 @@ sub process { } } + # : when part of a bitfield + } elsif ($opv eq ':B') { + if ($ctx =~ /.xW/) { + if (ERROR("SPACING", + "spaces prohibited after that '$op' $at\n" . $hereptr)) { + $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]); + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + # , must have a space on the right. } elsif ($op eq ',') { if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
Signature · 1 line
1.8.4.rc3
Joe Perches
maintainerQuoted 5 lines · Josh Triplett
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
There are a _bunch_ of different styles used for
alignment of bitfields.
$ grep -rPh --include=*.[ch] \ '(?:unsigned\s+|signed\s+|)(char|short|long|long\s+long|\w+_t|(?:__|)(?:u|s)(?:8|16|32|64))\s+\w+\s*:\s*\d+\s*(?:,|;)' *
spaces before colon
spaces after colon
aligned on bitfield size
I'd just as soon make it a --strict check.
Quoted 10 lines · Joe Perches
Quoted 5 lines · Josh Triplett
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
There are a _bunch_ of different styles used for
alignment of bitfields.
Quoted 8 lines
$ grep -rPh --include=*.[ch] \ '(?:unsigned\s+|signed\s+|)(char|short|long|long\s+long|\w+_t|(?:__|)(?:u|s)(?:8|16|32|64))\s+\w+\s*:\s*\d+\s*(?:,|;)' *spaces before colon
spaces after colon
aligned on bitfield sizeI'd just as soon make it a --strict check.
I'd be fine with removing the check entirely, or making it --strict; however, even for --strict mode I'd suggest applying this patch, as I don't think checkpatch should ever prohibit spaces before the ':'.
- Josh Triplett
Joe Perches
maintainerQuoted 18 lines · Josh Triplett
Quoted 17 lines · Joe Perches
Quoted 5 lines · Josh Triplett
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
There are a _bunch_ of different styles used for
alignment of bitfields.$ grep -rPh --include=*.[ch] \ '(?:unsigned\s+|signed\s+|)(char|short|long|long\s+long|\w+_t|(?:__|)(?:u|s)(?:8|16|32|64))\s+\w+\s*:\s*\d+\s*(?:,|;)' *spaces before colon
spaces after colon
aligned on bitfield size
Quoted 5 lines
Quoted 1 line
I'd just as soon make it a --strict check.
I'd be fine with removing the check entirely, or making it --strict; however, even for --strict mode I'd suggest applying this patch, as I don't think checkpatch should ever prohibit spaces before the ':'.
Maybe something like that patch, but spaces probably should be prohibited after the : in a bitfield either.
This style is pretty common
u32 dma_address0 :30; u32 dma_0No_update : 1; u32 dma_0start : 1; u32 dma_addr_size :24; u32 DMA_maxpackets : 8;
Quoted 28 lines · Joe Perches
Quoted 18 lines · Josh Triplett
Quoted 17 lines · Joe Perches
Quoted 5 lines · Josh Triplett
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
There are a _bunch_ of different styles used for
alignment of bitfields.$ grep -rPh --include=*.[ch] \ '(?:unsigned\s+|signed\s+|)(char|short|long|long\s+long|\w+_t|(?:__|)(?:u|s)(?:8|16|32|64))\s+\w+\s*:\s*\d+\s*(?:,|;)' *spaces before colon
spaces after colon
aligned on bitfield sizeQuoted 5 lines
Quoted 1 line
I'd just as soon make it a --strict check.
I'd be fine with removing the check entirely, or making it --strict; however, even for --strict mode I'd suggest applying this patch, as I don't think checkpatch should ever prohibit spaces before the ':'.
Maybe something like that patch, but spaces probably should be prohibited after the : in a bitfield either.
Quoted 7 lines
This style is pretty common
u32 dma_address0 :30; u32 dma_0No_update : 1; u32 dma_0start : 1; u32 dma_addr_size :24; u32 DMA_maxpackets : 8;
I'm fine with just dropping the check entirely; want a patch for that instead? It's a much simpler patch.
- Josh Triplett
Joe Perches
maintainerQuoted 31 lines · Josh Triplett
Quoted 30 lines · Joe Perches
Quoted 18 lines · Josh Triplett
Quoted 17 lines · Joe Perches
Quoted 5 lines · Josh Triplett
checkpatch warns about spaces both before and after the ':' separating a bitfield name from its width. However, many drivers do put space before the : to line up the widths, which makes the definition significantly more readable; checkpatch should not warn about that. Remove the warning for space before the ':' of a bitfield.
There are a _bunch_ of different styles used for
alignment of bitfields.$ grep -rPh --include=*.[ch] \ '(?:unsigned\s+|signed\s+|)(char|short|long|long\s+long|\w+_t|(?:__|)(?:u|s)(?:8|16|32|64))\s+\w+\s*:\s*\d+\s*(?:,|;)' *spaces before colon
spaces after colon
aligned on bitfield sizeQuoted 5 lines
Quoted 1 line
I'd just as soon make it a --strict check.
I'd be fine with removing the check entirely, or making it --strict; however, even for --strict mode I'd suggest applying this patch, as I don't think checkpatch should ever prohibit spaces before the ':'.
Maybe something like that patch, but spaces probably should be prohibited after the : in a bitfield either.
This style is pretty common
Quoted 8 lines
Quoted 5 lines
u32 dma_address0 :30; u32 dma_0No_update : 1; u32 dma_0start : 1; u32 dma_addr_size :24; u32 DMA_maxpackets : 8;I'm fine with just dropping the check entirely; want a patch for that instead? It's a much simpler patch.
Maybe Andy has an opinion? He's the one that
wrote almost all of these SPACING checks.