Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

checkpatch: improve blank line after declaration test

Avoid multiple false positives by ignoring attributes.

Various attributes like volatile and ____cacheline_aligned_in_smp cause
checkpatch to emit invalid "Missing a blank line after declarations"
messages.

Use copies of $sline and $prevline, remove $Attribute and $Sparse, and use
the existing tests to avoid these false positives.

Miscellanea:

o Add volatile to $Attribute

This also reduces checkpatch runtime a bit by moving the indentation
comparison test to the start of the block to avoid multiple unnecessary
regex tests.

Link: https://lkml.kernel.org/r/9015fd00742bf4e5b824ad6d7fd7189530958548.camel@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joe Perches and committed by
Linus Torvalds
b5e8736a 4945cca2

+29 -23
+29 -23
scripts/checkpatch.pl
··· 382 382 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check 383 383 our $Attribute = qr{ 384 384 const| 385 + volatile| 385 386 __percpu| 386 387 __nocast| 387 388 __safe| ··· 3777 3776 } 3778 3777 3779 3778 # check for missing blank lines after declarations 3780 - if ($sline =~ /^\+\s+\S/ && #Not at char 1 3781 - # actual declarations 3782 - ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || 3779 + # (declarations must have the same indentation and not be at the start of line) 3780 + if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) { 3781 + # use temporaries 3782 + my $sl = $sline; 3783 + my $pl = $prevline; 3784 + # remove $Attribute/$Sparse uses to simplify comparisons 3785 + $sl =~ s/\b(?:$Attribute|$Sparse)\b//g; 3786 + $pl =~ s/\b(?:$Attribute|$Sparse)\b//g; 3787 + if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || 3783 3788 # function pointer declarations 3784 - $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || 3789 + $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || 3785 3790 # foo bar; where foo is some local typedef or #define 3786 - $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || 3791 + $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || 3787 3792 # known declaration macros 3788 - $prevline =~ /^\+\s+$declaration_macros/) && 3793 + $pl =~ /^\+\s+$declaration_macros/) && 3789 3794 # for "else if" which can look like "$Ident $Ident" 3790 - !($prevline =~ /^\+\s+$c90_Keywords\b/ || 3795 + !($pl =~ /^\+\s+$c90_Keywords\b/ || 3791 3796 # other possible extensions of declaration lines 3792 - $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || 3797 + $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || 3793 3798 # not starting a section or a macro "\" extended line 3794 - $prevline =~ /(?:\{\s*|\\)$/) && 3799 + $pl =~ /(?:\{\s*|\\)$/) && 3795 3800 # looks like a declaration 3796 - !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || 3801 + !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || 3797 3802 # function pointer declarations 3798 - $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || 3803 + $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || 3799 3804 # foo bar; where foo is some local typedef or #define 3800 - $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || 3805 + $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || 3801 3806 # known declaration macros 3802 - $sline =~ /^\+\s+$declaration_macros/ || 3807 + $sl =~ /^\+\s+$declaration_macros/ || 3803 3808 # start of struct or union or enum 3804 - $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ || 3809 + $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ || 3805 3810 # start or end of block or continuation of declaration 3806 - $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || 3811 + $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || 3807 3812 # bitfield continuation 3808 - $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || 3813 + $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || 3809 3814 # other possible extensions of declaration lines 3810 - $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) && 3811 - # indentation of previous and current line are the same 3812 - (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) { 3813 - if (WARN("LINE_SPACING", 3814 - "Missing a blank line after declarations\n" . $hereprev) && 3815 - $fix) { 3816 - fix_insert_line($fixlinenr, "\+"); 3815 + $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) { 3816 + if (WARN("LINE_SPACING", 3817 + "Missing a blank line after declarations\n" . $hereprev) && 3818 + $fix) { 3819 + fix_insert_line($fixlinenr, "\+"); 3820 + } 3817 3821 } 3818 3822 } 3819 3823