Skip to content

Commit ad4084a

Browse files
scripts: checkpatch: fix missing blank line detection
Fix checkpatch not warning when blank line after declaration is removed. Updated regexes to also handle context lines, ensuring consistent detection. Fixes: #98976 Signed-off-by: Vignesh Pandian <vignesh@aerlync.com>
1 parent a1b406d commit ad4084a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

scripts/checkpatch.pl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env perl
2-
# SPDX-License-Identifier: GPL-2.0
2+
# SPDX-License-Identifier: Apache-2.0
33
#
44
# (c) 2001, Dave Jones. (the file handling bit)
55
# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
66
# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
77
# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
88
# (c) 2010-2018 Joe Perches <joe@perches.com>
9+
# (c) 2025 Aerlync Labs Inc
910

1011
use strict;
1112
use warnings;
@@ -3521,39 +3522,39 @@ sub process {
35213522
}
35223523

35233524
# check for missing blank lines after declarations
3524-
if ($sline =~ /^\+\s+\S/ && #Not at char 1
3525+
if (($sline =~ /^\+\s+\S/ || $sline =~ /^\s+\S/) && # Not at char 1
35253526
# actual declarations
3526-
($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
3527+
($prevline =~ /^(\+|\s)\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
35273528
# function pointer declarations
3528-
$prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
3529+
$prevline =~ /^(\+|\s)\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
35293530
# foo bar; where foo is some local typedef or #define
3530-
$prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
3531+
$prevline =~ /^(\+|\s)\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
35313532
# known declaration macros
3532-
$prevline =~ /^\+\s+$declaration_macros/) &&
3533+
$prevline =~ /^(\+|\s)\s+$declaration_macros/) &&
35333534
# for "else if" which can look like "$Ident $Ident"
3534-
!($prevline =~ /^\+\s+$c90_Keywords\b/ ||
3535+
!($prevline =~ /^(\+|\s)\s+$c90_Keywords\b/ ||
35353536
# other possible extensions of declaration lines
35363537
$prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
35373538
# not starting a section or a macro "\" extended line
35383539
$prevline =~ /(?:\{\s*|\\)$/) &&
35393540
# looks like a declaration
3540-
!($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
3541+
!($sline =~ /^(\+|\s)\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
35413542
# function pointer declarations
3542-
$sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
3543+
$sline =~ /^(\+|\s)\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
35433544
# foo bar; where foo is some local typedef or #define
3544-
$sline =~ /^\+\s+(?:volatile\s+)?$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
3545+
$sline =~ /^(\+|\s)\s+(?:volatile\s+)?$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
35453546
# known declaration macros
3546-
$sline =~ /^\+\s+$declaration_macros/ ||
3547+
$sline =~ /^(\+|\s)\s+$declaration_macros/ ||
35473548
# start of struct or union or enum
3548-
$sline =~ /^\+\s+(?:volatile\s+)?(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
3549+
$sline =~ /^(\+|\s)\s+(?:volatile\s+)?(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
35493550
# start or end of block or continuation of declaration
3550-
$sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
3551+
$sline =~ /^(\+|\s)\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
35513552
# bitfield continuation
3552-
$sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
3553+
$sline =~ /^(\+|\s)\s+$Ident\s*:\s*\d+\s*[,;]/ ||
35533554
# other possible extensions of declaration lines
3554-
$sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
3555+
$sline =~ /^(\+|\s)\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
35553556
# indentation of previous and current line are the same
3556-
(($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
3557+
(($prevline =~ /^(\+|\s)(\s+)\S/) && $sline =~ /^(\+|\s)$2\S/)) {
35573558
if (WARN("LINE_SPACING",
35583559
"Missing a blank line after declarations\n" . $hereprev) &&
35593560
$fix) {

0 commit comments

Comments
 (0)