History

checkpatch: make types found in a source file/patch local

checkpatch uses various cues in its input patches and files to discover the names of user-defined types and modifiers. It then uses that information when processing expressions to discover potential style issues. Unfortunately, in rare cases, this means that checkpatch may give different results if you run it on several input files in one execution, or one by one! The reason is that it may identify a type (or something that looks like a type) in one file, and then carry this information over when processing a different file. For example, drivers/staging/media/bcm2048/radio-bcm2048.c contains this line (in a macro): size value; and drivers/staging/media/davinci_vpfe/vpfe_video.c has this line: while (size * *nbuffers > vpfe_dev->video_limit) If checkpatch processes these 2 files in a single command like: ./scripts/checkpatch.pl -f $file1 $file2 the (spurious) "size" type detected in the first file will cause it to flag the second file for improper use of the pointer dereference operator. To fix this, store types and modifiers found in a file in separate arrays from built-in ones, and reset the arrays of types and modifiers found in files at the beginning of each new source file.

Alex Dowad committed 11 years ago

Commit 485ff231 parent e6176fa1 file · +9 −4Browse files

Unified · Split

scripts/checkpatch.pl+9−4
@@ -423,6 +423,7 @@ our @typeList = ( · 422 unmodified lines
423423 qr{${Ident}_handler_fn},
424424 @typeListMisordered,
425425 );
426+our @typeListFile = ();
426427 our @typeListWithAttr = (
427428 @typeList,
428429 qr{struct\s+$InitAttribute\s+$Ident},
@@ -432,6 +433,7 @@ our @typeListWithAttr = ( · 3 unmodified lines
432433 our @modifierList = (
433434 qr{fastcall},
434435 );
436+our @modifierListFile = ();
435437
436438 our @mode_permission_funcs = (
437439 ["module_param", 3],
@@ -515,8 +517,8 @@ if ($codespell) { · 77 unmodified lines
515517 $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
516518
517519 sub build_types {
518− my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
519− my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
520+ my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
521+ my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
520522 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
521523 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
522524 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
@@ -748,6 +750,9 @@ for my $filename (@ARGV) { · 225 unmodified lines
748750 @fixed_inserted = ();
749751 @fixed_deleted = ();
750752 $fixlinenr = -1;
753+ @modifierListFile = ();
754+ @typeListFile = ();
755+ build_types();
751756 }
752757
753758 exit($exit);
@@ -1612,13 +1617,13 @@ sub possible { · 858 unmodified lines
16121617 for my $modifier (split(' ', $possible)) {
16131618 if ($modifier !~ $notPermitted) {
16141619 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
1615− push(@modifierList, $modifier);
1620+ push(@modifierListFile, $modifier);
16161621 }
16171622 }
16181623
16191624 } else {
16201625 warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
1621− push(@typeList, $possible);
1626+ push(@typeListFile, $possible);
16221627 }
16231628 build_types();
16241629 } else {