* [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
@ 2021-01-05 9:35 Dwaipayan Ray
2021-01-05 10:01 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Dwaipayan Ray @ 2021-01-05 9:35 UTC (permalink / raw)
To: joe; +Cc: dwaipayanray1, linux-kernel-mentees, linux-kernel
Perl 5.22 onwards require that "A literal "{" should now be
escaped in a pattern".
checkpatch contains several literal "{". Fix such instances
by preceding them with a backslash.
Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
scripts/checkpatch.pl | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 00085308ed9d..8e80a158bf5a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1652,7 +1652,7 @@ sub statement_block_size {
my ($stmt) = @_;
$stmt =~ s/(^|\n)./$1/g;
- $stmt =~ s/^\s*{//;
+ $stmt =~ s/^\s*\{//;
$stmt =~ s/}\s*$//;
$stmt =~ s/^\s*//;
$stmt =~ s/\s*$//;
@@ -2036,7 +2036,7 @@ sub annotate_values {
print "ASSIGN($1)\n" if ($dbg_values > 1);
$type = 'N';
- } elsif ($cur =~/^(;|{|})/) {
+ } elsif ($cur =~ /^(;|\{|\})/) {
print "END($1)\n" if ($dbg_values > 1);
$type = 'E';
$av_pend_colon = 'O';
@@ -3913,7 +3913,7 @@ sub process {
# it there is no point in retrying a statement scan
# until we hit end of it.
my $frag = $stat; $frag =~ s/;+\s*$//;
- if ($frag !~ /(?:{|;)/) {
+ if ($frag !~ /(?:\{|;)/) {
#print "skip<$line_nr_next>\n";
$suppress_statement = $line_nr_next;
}
@@ -4029,7 +4029,7 @@ sub process {
#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
- if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
+ if ($ctx !~ /\{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*\{/) {
ERROR("OPEN_BRACE",
"that open brace { should be on the previous line\n" .
"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
@@ -4080,7 +4080,7 @@ sub process {
my $continuation = 0;
my $check = 0;
$s =~ s/^.*\bdo\b//;
- $s =~ s/^\s*{//;
+ $s =~ s/^\s*\{//;
if ($s =~ s/^\s*\\//) {
$continuation = 1;
}
@@ -4235,7 +4235,7 @@ sub process {
}
# check for initialisation to aggregates open brace on the next line
- if ($line =~ /^.\s*{/ &&
+ if ($line =~ /^.\s*\{/ &&
$prevline =~ /(?:^|[^=])=\s*$/) {
if (ERROR("OPEN_BRACE",
"that open brace { should be on the previous line\n" . $hereprev) &&
@@ -4243,7 +4243,7 @@ sub process {
fix_delete_line($fixlinenr - 1, $prevrawline);
fix_delete_line($fixlinenr, $rawline);
my $fixedline = $prevrawline;
- $fixedline =~ s/\s*=\s*$/ = {/;
+ $fixedline =~ s/\s*=\s*$/ = \{/;
fix_insert_line($fixlinenr, $fixedline);
$fixedline = $line;
$fixedline =~ s/^(.\s*)\{\s*/$1/;
@@ -4617,7 +4617,7 @@ sub process {
}
# open braces for enum, union and struct go on the same line.
- if ($line =~ /^.\s*{/ &&
+ if ($line =~ /^.\s*\{/ &&
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
if (ERROR("OPEN_BRACE",
"open brace '{' following $1 go on the same line\n" . $hereprev) &&
@@ -5345,7 +5345,7 @@ sub process {
# Check for illegal assignment in if conditional -- and check for trailing
# statements after the conditional.
- if ($line =~ /do\s*(?!{)/) {
+ if ($line =~ /do\s*(?!\{)/) {
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
ctx_statement_block($linenr, $realcnt, 0)
if (!defined $stat);
@@ -5403,7 +5403,7 @@ sub process {
substr($s, 0, length($c), '');
$s =~ s/\n.*//g;
$s =~ s/$;//g; # Remove any comments
- if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
+ if (length($c) && $s !~ /^\s*\{?\s*\\*\s*$/ &&
$c !~ /}\s*while\s*/)
{
# Find out how long the conditional actually is.
@@ -5442,7 +5442,7 @@ sub process {
if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
my $s = $1;
$s =~ s/$;//g; # Remove any comments
- if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
+ if ($s !~ /^\s*(?:\sif|(?:\{|)\s*\\?\s*$)/) {
ERROR("TRAILING_STATEMENTS",
"trailing statements should be on next line\n" . $herecurr);
}
@@ -5659,7 +5659,7 @@ sub process {
$dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
$dstat !~ /^for\s*$Constant$/ && # for (...)
$dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
- $dstat !~ /^do\s*{/ && # do {...
+ $dstat !~ /^do\s*\{/ && # do {...
$dstat !~ /^\(\{/ && # ({...
$ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
{
@@ -5811,7 +5811,7 @@ sub process {
substr($block, 0, length($cond), '');
- $seen++ if ($block =~ /^\s*{/);
+ $seen++ if ($block =~ /^\s*\{/);
#print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
if (statement_lines($cond) > 1) {
@@ -5909,7 +5909,7 @@ sub process {
fix_delete_line($fixlinenr - 1, $prevrawline);
}
}
- if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
+ if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*\{\s*$/)) {
if (CHK("BRACES",
"Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
$fix) {
--
2.27.0
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
2021-01-05 9:35 [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces Dwaipayan Ray
@ 2021-01-05 10:01 ` Joe Perches
2021-01-05 10:08 ` Dwaipayan Ray
2021-01-05 10:35 ` David Laight
0 siblings, 2 replies; 6+ messages in thread
From: Joe Perches @ 2021-01-05 10:01 UTC (permalink / raw)
To: Dwaipayan Ray; +Cc: linux-kernel-mentees, linux-kernel
On Tue, 2021-01-05 at 15:05 +0530, Dwaipayan Ray wrote:
> Perl 5.22 onwards require that "A literal "{" should now be
> escaped in a pattern".
Not quite correct.
> checkpatch contains several literal "{". Fix such instances
> by preceding them with a backslash.
Not all literal left braces need to be escaped.
https://www.perlmonks.org/?node_id=1191981
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -2036,7 +2036,7 @@ sub annotate_values {
> print "ASSIGN($1)\n" if ($dbg_values > 1);
> $type = 'N';
>
>
> - } elsif ($cur =~/^(;|{|})/) {
> + } elsif ($cur =~ /^(;|\{|\})/) {
Like this one. And why escape the right brace too?
> print "END($1)\n" if ($dbg_values > 1);
> $type = 'E';
> $av_pend_colon = 'O';
> @@ -3913,7 +3913,7 @@ sub process {
> # it there is no point in retrying a statement scan
> # until we hit end of it.
> my $frag = $stat; $frag =~ s/;+\s*$//;
> - if ($frag !~ /(?:{|;)/) {
> + if ($frag !~ /(?:\{|;)/) {
And here.
etc...
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
2021-01-05 10:01 ` Joe Perches
@ 2021-01-05 10:08 ` Dwaipayan Ray
2021-01-05 10:35 ` David Laight
1 sibling, 0 replies; 6+ messages in thread
From: Dwaipayan Ray @ 2021-01-05 10:08 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-kernel-mentees, linux-kernel
On Tue, Jan 5, 2021 at 3:31 PM Joe Perches <joe@perches.com> wrote:
>
> On Tue, 2021-01-05 at 15:05 +0530, Dwaipayan Ray wrote:
> > Perl 5.22 onwards require that "A literal "{" should now be
> > escaped in a pattern".
>
> Not quite correct.
>
> > checkpatch contains several literal "{". Fix such instances
> > by preceding them with a backslash.
>
> Not all literal left braces need to be escaped.
> https://www.perlmonks.org/?node_id=1191981
>
Thanks, I got this from perl diag:
"
The contexts where no warnings or errors are raised are:
as the first character in a pattern, or following "^" indicating to
anchor the match to the beginning of a line.
as the first character following a "|" indicating alternation.
as the first character in a parenthesized grouping like
/foo({bar)/
/foo(?:{bar)/
as the first character following a quantifier
/\s*{/
"
I will update the patch with the above in mind.
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -2036,7 +2036,7 @@ sub annotate_values {
> > print "ASSIGN($1)\n" if ($dbg_values > 1);
> > $type = 'N';
> >
> >
> > - } elsif ($cur =~/^(;|{|})/) {
> > + } elsif ($cur =~ /^(;|\{|\})/) {
>
> Like this one. And why escape the right brace too?
>
The right brace escape was just for the expression to look a bit even.
It's unneeded, will remove these too.
> > print "END($1)\n" if ($dbg_values > 1);
> > $type = 'E';
> > $av_pend_colon = 'O';
> > @@ -3913,7 +3913,7 @@ sub process {
> > # it there is no point in retrying a statement scan
> > # until we hit end of it.
> > my $frag = $stat; $frag =~ s/;+\s*$//;
> > - if ($frag !~ /(?:{|;)/) {
> > + if ($frag !~ /(?:\{|;)/) {
>
> And here.
>
> etc...
>
Thank you,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
2021-01-05 10:01 ` Joe Perches
2021-01-05 10:08 ` Dwaipayan Ray
@ 2021-01-05 10:35 ` David Laight
2021-01-05 10:49 ` Joe Perches
1 sibling, 1 reply; 6+ messages in thread
From: David Laight @ 2021-01-05 10:35 UTC (permalink / raw)
To: 'Joe Perches', Dwaipayan Ray; +Cc: linux-kernel-mentees, linux-kernel
From: Joe Perches
> Sent: 05 January 2021 10:01
>
> On Tue, 2021-01-05 at 15:05 +0530, Dwaipayan Ray wrote:
> > Perl 5.22 onwards require that "A literal "{" should now be
> > escaped in a pattern".
Sounds like a good reason to never use perl :-)
> Not quite correct.
>
> > checkpatch contains several literal "{". Fix such instances
> > by preceding them with a backslash.
>
> Not all literal left braces need to be escaped.
> https://www.perlmonks.org/?node_id=1191981
>
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -2036,7 +2036,7 @@ sub annotate_values {
> > print "ASSIGN($1)\n" if ($dbg_values > 1);
> > $type = 'N';
> >
> >
> > - } elsif ($cur =~/^(;|{|})/) {
> > + } elsif ($cur =~ /^(;|\{|\})/) {
isn't (;|{|}) much the same as [;{}] ??
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
2021-01-05 10:35 ` David Laight
@ 2021-01-05 10:49 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2021-01-05 10:49 UTC (permalink / raw)
To: David Laight, Dwaipayan Ray; +Cc: linux-kernel-mentees, linux-kernel
On Tue, 2021-01-05 at 10:35 +0000, David Laight wrote:
> From: Joe Perches
> > Sent: 05 January 2021 10:01
> >
> > On Tue, 2021-01-05 at 15:05 +0530, Dwaipayan Ray wrote:
> > > Perl 5.22 onwards require that "A literal "{" should now be
> > > escaped in a pattern".
>
> Sounds like a good reason to never use perl :-)
>
> > Not quite correct.
> >
> > > checkpatch contains several literal "{". Fix such instances
> > > by preceding them with a backslash.
> >
> > Not all literal left braces need to be escaped.
> > https://www.perlmonks.org/?node_id=1191981
> >
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > []
> > > @@ -2036,7 +2036,7 @@ sub annotate_values {
> > > print "ASSIGN($1)\n" if ($dbg_values > 1);
> > > $type = 'N';
> > >
> > >
> > > - } elsif ($cur =~/^(;|{|})/) {
> > > + } elsif ($cur =~ /^(;|\{|\})/) {
>
> isn't (;|{|}) much the same as [;{}] ??
Yes, but without the capture, so /^([;{}])/ would be the same.
I presume the | style was used for consistency with other uses
in the same block.
Andy Whitcroft wrote that bit a long time ago.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces
@ 2021-01-02 4:39 Dwaipayan Ray
0 siblings, 0 replies; 6+ messages in thread
From: Dwaipayan Ray @ 2021-01-02 4:39 UTC (permalink / raw)
To: lukas.bulwahn; +Cc: Dwaipayan Ray, linux-kernel-mentees
Perl 5.22 onwards require that "A literal "{" should now be
escaped in a pattern".
checkpatch contains several literal "{". Fix such instances
by preceding them with a backslash.
Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
scripts/checkpatch.pl | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 00085308ed9d..8e80a158bf5a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1652,7 +1652,7 @@ sub statement_block_size {
my ($stmt) = @_;
$stmt =~ s/(^|\n)./$1/g;
- $stmt =~ s/^\s*{//;
+ $stmt =~ s/^\s*\{//;
$stmt =~ s/}\s*$//;
$stmt =~ s/^\s*//;
$stmt =~ s/\s*$//;
@@ -2036,7 +2036,7 @@ sub annotate_values {
print "ASSIGN($1)\n" if ($dbg_values > 1);
$type = 'N';
- } elsif ($cur =~/^(;|{|})/) {
+ } elsif ($cur =~ /^(;|\{|\})/) {
print "END($1)\n" if ($dbg_values > 1);
$type = 'E';
$av_pend_colon = 'O';
@@ -3913,7 +3913,7 @@ sub process {
# it there is no point in retrying a statement scan
# until we hit end of it.
my $frag = $stat; $frag =~ s/;+\s*$//;
- if ($frag !~ /(?:{|;)/) {
+ if ($frag !~ /(?:\{|;)/) {
#print "skip<$line_nr_next>\n";
$suppress_statement = $line_nr_next;
}
@@ -4029,7 +4029,7 @@ sub process {
#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
- if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
+ if ($ctx !~ /\{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*\{/) {
ERROR("OPEN_BRACE",
"that open brace { should be on the previous line\n" .
"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
@@ -4080,7 +4080,7 @@ sub process {
my $continuation = 0;
my $check = 0;
$s =~ s/^.*\bdo\b//;
- $s =~ s/^\s*{//;
+ $s =~ s/^\s*\{//;
if ($s =~ s/^\s*\\//) {
$continuation = 1;
}
@@ -4235,7 +4235,7 @@ sub process {
}
# check for initialisation to aggregates open brace on the next line
- if ($line =~ /^.\s*{/ &&
+ if ($line =~ /^.\s*\{/ &&
$prevline =~ /(?:^|[^=])=\s*$/) {
if (ERROR("OPEN_BRACE",
"that open brace { should be on the previous line\n" . $hereprev) &&
@@ -4243,7 +4243,7 @@ sub process {
fix_delete_line($fixlinenr - 1, $prevrawline);
fix_delete_line($fixlinenr, $rawline);
my $fixedline = $prevrawline;
- $fixedline =~ s/\s*=\s*$/ = {/;
+ $fixedline =~ s/\s*=\s*$/ = \{/;
fix_insert_line($fixlinenr, $fixedline);
$fixedline = $line;
$fixedline =~ s/^(.\s*)\{\s*/$1/;
@@ -4617,7 +4617,7 @@ sub process {
}
# open braces for enum, union and struct go on the same line.
- if ($line =~ /^.\s*{/ &&
+ if ($line =~ /^.\s*\{/ &&
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
if (ERROR("OPEN_BRACE",
"open brace '{' following $1 go on the same line\n" . $hereprev) &&
@@ -5345,7 +5345,7 @@ sub process {
# Check for illegal assignment in if conditional -- and check for trailing
# statements after the conditional.
- if ($line =~ /do\s*(?!{)/) {
+ if ($line =~ /do\s*(?!\{)/) {
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
ctx_statement_block($linenr, $realcnt, 0)
if (!defined $stat);
@@ -5403,7 +5403,7 @@ sub process {
substr($s, 0, length($c), '');
$s =~ s/\n.*//g;
$s =~ s/$;//g; # Remove any comments
- if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
+ if (length($c) && $s !~ /^\s*\{?\s*\\*\s*$/ &&
$c !~ /}\s*while\s*/)
{
# Find out how long the conditional actually is.
@@ -5442,7 +5442,7 @@ sub process {
if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
my $s = $1;
$s =~ s/$;//g; # Remove any comments
- if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
+ if ($s !~ /^\s*(?:\sif|(?:\{|)\s*\\?\s*$)/) {
ERROR("TRAILING_STATEMENTS",
"trailing statements should be on next line\n" . $herecurr);
}
@@ -5659,7 +5659,7 @@ sub process {
$dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
$dstat !~ /^for\s*$Constant$/ && # for (...)
$dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
- $dstat !~ /^do\s*{/ && # do {...
+ $dstat !~ /^do\s*\{/ && # do {...
$dstat !~ /^\(\{/ && # ({...
$ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
{
@@ -5811,7 +5811,7 @@ sub process {
substr($block, 0, length($cond), '');
- $seen++ if ($block =~ /^\s*{/);
+ $seen++ if ($block =~ /^\s*\{/);
#print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
if (statement_lines($cond) > 1) {
@@ -5909,7 +5909,7 @@ sub process {
fix_delete_line($fixlinenr - 1, $prevrawline);
}
}
- if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
+ if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*\{\s*$/)) {
if (CHK("BRACES",
"Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
$fix) {
--
2.27.0
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-05 12:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 9:35 [Linux-kernel-mentees] [PATCH] checkpatch: fix unescaped left braces Dwaipayan Ray
2021-01-05 10:01 ` Joe Perches
2021-01-05 10:08 ` Dwaipayan Ray
2021-01-05 10:35 ` David Laight
2021-01-05 10:49 ` Joe Perches
-- strict thread matches above, loose matches on Subject: below --
2021-01-02 4:39 Dwaipayan Ray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).