Messages in this thread Patch in this message | | | Subject | Re: [PATCH v2] checkpatch: fix CONST_STRUCT when const_structs.checkpatch is missing | From | Joe Perches <> | Date | Tue, 23 Jun 2020 09:48:19 -0700 |
| |
Hi again.
On Tue, 2020-06-23 at 11:37 +0100, Quentin Monnet wrote: > Checkpatch reports warnings when some specific structs are not declared > as const in the code. The list of structs to consider was initially > defined in the checkpatch.pl script itself, but it was later moved to an > external file (scripts/const_structs.checkpatch), in commit bf1fa1dae68e > ("checkpatch: externalize the structs that should be const"). This > introduced two minor issues: [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -770,7 +770,7 @@ sub read_words { > next; > } > > - $$wordsRef .= '|' if ($$wordsRef ne ""); > + $$wordsRef .= '|' if (defined($$wordsRef) && $$wordsRef ne "");
perl is a weird language and the $$wordsRef ne "" test isn't required as the append will work even if the thing being appended to isn't defined.
You can read the perlsyn docs http://perldoc.perl.org/perlsyn.html or https://stackoverflow.com/questions/2166575/when-is-it-ok-to-use-an-undefined-variable-in-perl-with-warnings-enabled
so perhaps remove the test and improve the additional $typedefsfile use too --- scripts/checkpatch.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b06093777fd8..9210267a7771 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -62,7 +62,7 @@ my $spelling_file = "$D/spelling.txt"; my $codespell = 0; my $codespellfile = "/usr/share/codespell/dictionary.txt"; my $conststructsfile = "$D/const_structs.checkpatch"; -my $typedefsfile = ""; +my $typedefsfile; my $color = "auto"; my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE # git output parsing needs US English output, so first set backtick child process LANGUAGE @@ -770,7 +770,7 @@ sub read_words { next; } - $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= '|' if (defined($$wordsRef)); $$wordsRef .= $line; } close($file); @@ -780,16 +780,18 @@ sub read_words { return 0; } -my $const_structs = ""; -read_words(\$const_structs, $conststructsfile) - or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; +my $const_structs; +if (show_type("CONST_STRUCT")) { + read_words(\$const_structs, $conststructsfile) + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; -my $typeOtherTypedefs = ""; -if (length($typedefsfile)) { + +if (defined($typedefsfile)) { + my $typeOtherTypedefs; read_words(\$typeOtherTypedefs, $typedefsfile) or warn "No additional types will be considered - file '$typedefsfile': $!\n"; + $typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs); } -$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); sub build_types { my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; @@ -6660,7 +6662,8 @@ sub process { # check for various structs that are normally const (ops, kgdb, device_tree) # and avoid what seem like struct definitions 'struct foo {' - if ($line !~ /\bconst\b/ && + if (defined($const_structs) && + $line !~ /\bconst\b/ && $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { WARN("CONST_STRUCT", "struct $1 should normally be const\n" . $herecurr);
| |