From 00a25db9ea6168d60e60cfdcb6fb6ba065236802 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sat, 18 Apr 2020 17:20:14 -0400 Subject: [PATCH] checkpatch.pl: Escape curly braces in regexes Unescaped curly braces have been deprecated since Perl 5.26 and are illegal in Perl 5.30. I copied the relevant lines from the latest kernel source, so we'll inherit a couple other improvements as well. --- checkpatch.pl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/checkpatch.pl b/checkpatch.pl index 86155bdb..eee8d6ee 100755 --- a/checkpatch.pl +++ b/checkpatch.pl @@ -2419,8 +2419,10 @@ sub process { # function brace can't be on same line, except for #defines of do while, # or if closed on same line - if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and - !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { + if ($line =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && + $line !~ /\#\s*define\b.*do\s*\{/ && + $line !~ /}/) { + ERROR("OPEN_BRACE", "open brace '{' following function declarations go on the next line\n" . $herecurr); } @@ -2847,12 +2849,12 @@ sub process { #need space before brace following if, while, etc - if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || - $line =~ /do{/) { + if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) || + $line =~ /\b(?:else|do)\{/) { if (ERROR("SPACING", "space required before the open brace '{'\n" . $herecurr) && $fix) { - $fixed[$linenr - 1] =~ s/^(\+.*(?:do|\))){/$1 {/; + $fixed[$linenr - 1] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/; } } @@ -3198,7 +3200,7 @@ sub process { $dstat !~ /^for\s*$Constant$/ && # for (...) $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() $dstat !~ /^do\s*{/ && # do {... - $dstat !~ /^\({/ && # ({... + $dstat !~ /^\(\{/ && # ({... $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) { $ctx =~ s/\n*$//;