diff options
author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2021-09-18 11:52:12 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-09-21 18:32:53 +0200 |
commit | f090db43958a0a0b6a920d25f56a79cce2ec8d1b (patch) | |
tree | 230a934ee4149a93137b3ddc9d4c7dfbd364a69b /scripts/get_abi.pl | |
parent | ab9c14805b379b7890f2e162149b6978b2a75986 (diff) |
scripts: get_abi.pl: Check for missing symbols at the ABI specs
Check for the symbols that exists under /sys but aren't
defined at Documentation/ABI.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/958e4f3a319148af6d847c0df95e35426f9c4c5f.1631957565.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'scripts/get_abi.pl')
-rwxr-xr-x | scripts/get_abi.pl | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/scripts/get_abi.pl b/scripts/get_abi.pl index cfc107df59f4..78364c4c4967 100755 --- a/scripts/get_abi.pl +++ b/scripts/get_abi.pl @@ -13,7 +13,9 @@ my $help = 0; my $man = 0; my $debug = 0; my $enable_lineno = 0; +my $show_warnings = 1; my $prefix="Documentation/ABI"; +my $sysfs_prefix="/sys"; # # If true, assumes that the description is formatted with ReST @@ -36,7 +38,7 @@ pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2); my ($cmd, $arg) = @ARGV; -pod2usage(2) if ($cmd ne "search" && $cmd ne "rest" && $cmd ne "validate"); +pod2usage(2) if ($cmd ne "search" && $cmd ne "rest" && $cmd ne "validate" && $cmd ne "undefined"); pod2usage(2) if ($cmd eq "search" && !$arg); require Data::Dumper if ($debug); @@ -50,6 +52,8 @@ my %symbols; sub parse_error($$$$) { my ($file, $ln, $msg, $data) = @_; + return if (!$show_warnings); + $data =~ s/\s+$/\n/; print STDERR "Warning: file $file#$ln:\n\t$msg"; @@ -521,11 +525,88 @@ sub search_symbols { } } +# Exclude /sys/kernel/debug and /sys/kernel/tracing from the search path +sub skip_debugfs { + if (($File::Find::dir =~ m,^/sys/kernel,)) { + return grep {!/(debug|tracing)/ } @_; + } + + if (($File::Find::dir =~ m,^/sys/fs,)) { + return grep {!/(pstore|bpf|fuse)/ } @_; + } + + return @_ +} + +my %leaf; + +my $escape_symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x29\x2b-\x2d\x3a-\x40\x7b-\xff]) }x; +sub parse_existing_sysfs { + my $file = $File::Find::name; + + my $mode = (stat($file))[2]; + return if ($mode & S_IFDIR); + + my $leave = $file; + $leave =~ s,.*/,,; + + if (defined($leaf{$leave})) { + # FIXME: need to check if the path makes sense + my $what = $leaf{$leave}; + + $what =~ s/,/ /g; + + $what =~ s/\<[^\>]+\>/.*/g; + $what =~ s/\{[^\}]+\}/.*/g; + $what =~ s/\[[^\]]+\]/.*/g; + $what =~ s,/\.\.\./,/.*/,g; + $what =~ s,/\*/,/.*/,g; + + $what =~ s/\s+/ /g; + + # Escape all other symbols + $what =~ s/$escape_symbols/\\$1/g; + + foreach my $i (split / /,$what) { + if ($file =~ m#^$i$#) { +# print "$file: $i: OK!\n"; + return; + } + } + + print "$file: $leave is defined at $what\n"; + + return; + } + + print "$file not found.\n"; +} + +sub undefined_symbols { + foreach my $w (sort keys %data) { + foreach my $what (split /\xac /,$w) { + my $leave = $what; + $leave =~ s,.*/,,; + + if (defined($leaf{$leave})) { + $leaf{$leave} .= " " . $what; + } else { + $leaf{$leave} = $what; + } + } + } + + find({wanted =>\&parse_existing_sysfs, preprocess =>\&skip_debugfs, no_chdir => 1}, $sysfs_prefix); +} + # Ensure that the prefix will always end with a slash # While this is not needed for find, it makes the patch nicer # with --enable-lineno $prefix =~ s,/?$,/,; +if ($cmd eq "undefined" || $cmd eq "search") { + $show_warnings = 0; +} # # Parses all ABI files located at $prefix dir # @@ -536,7 +617,9 @@ print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug); # # Handles the command # -if ($cmd eq "search") { +if ($cmd eq "undefined") { + undefined_symbols; +} elsif ($cmd eq "search") { search_symbols; } else { if ($cmd eq "rest") { @@ -575,6 +658,9 @@ B<rest> - output the ABI in ReST markup language B<validate> - validate the ABI contents +B<undefined> - existing symbols at the system that aren't + defined at Documentation/ABI + =back =head1 OPTIONS |