Commit 69078651 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: improve the indented label test

checkpatch identifies a label only when a terminating colon
immediately follows an identifier.

Bitfield definitions can appear to be labels so ignore any
spaces between the identifier terminating colon and any digit
that may be used to define a bitfield length.

Miscellanea:

o Improve the initial checkpatch comment
o Use the more typical '&&' instead of 'and'
o Require the initial label character to be a non-digit
  (Can't use $Ident here because $Ident allows ## concatenation)
o Use $sline instead of $line to ignore comments
o Use '$sline !~ /.../' instead of '!($line =~ /.../)'

Link: https://lkml.kernel.org/r/b54d673e7cde7de5de0c9ba4dd57dd0858580ca4.camel@perches.comSigned-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Manikishan Ghantasala <manikishanghantasala@gmail.com>
Cc: Alex Elder <elder@ieee.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f9363b31
...@@ -5361,9 +5361,13 @@ sub process { ...@@ -5361,9 +5361,13 @@ sub process {
} }
} }
#goto labels aren't indented, allow a single space however # check that goto labels aren't indented (allow a single space indentation)
if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and # and ignore bitfield definitions like foo:1
!($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { # Strictly, labels can have whitespace after the identifier and before the :
# but this is not allowed here as many ?: uses would appear to be labels
if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
$sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
$sline !~ /^.\s+default:/) {
if (WARN("INDENTED_LABEL", if (WARN("INDENTED_LABEL",
"labels should not be indented\n" . $herecurr) && "labels should not be indented\n" . $herecurr) &&
$fix) { $fix) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment