All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Kees Cook <keescook@chromium.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Tony Luck <tony.luck@intel.com>, Yonghong Song <yhs@fb.com>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH 02/13] scripts: get_abi.pl: Check for missing symbols at the ABI specs
Date: Thu, 23 Sep 2021 15:30:00 +0200	[thread overview]
Message-ID: <8612c609e77b1b057172ab13685bdfd3ce37995f.1632402570.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1632402570.git.mchehab+huawei@kernel.org>

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>
---
 scripts/get_abi.pl | 90 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 88 insertions(+), 2 deletions(-)

diff --git a/scripts/get_abi.pl b/scripts/get_abi.pl
index 48077feea89c..e714bf75f5c2 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";
@@ -522,11 +526,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
 #
@@ -537,7 +618,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") {
@@ -576,6 +659,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
-- 
2.31.1


  parent reply	other threads:[~2021-09-23 13:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 13:29 [PATCH 00/13] get_abi.pl undefined: improve precision and performance Mauro Carvalho Chehab
2021-09-23 13:29 ` [PATCH 01/13] scripts: get_abi.pl: Better handle multiple What parameters Mauro Carvalho Chehab
2021-09-23 13:30 ` Mauro Carvalho Chehab [this message]
2021-09-23 13:30 ` [PATCH 03/13] scripts: get_abi.pl: detect softlinks Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 04/13] scripts: get_abi.pl: add an option to filter undefined results Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 05/13] scripts: get_abi.pl: don't skip what that ends with wildcards Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 06/13] scripts: get_abi.pl: Ignore fs/cgroup sysfs nodes earlier Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 07/13] scripts: get_abi.pl: add a graph to speedup the undefined algorithm Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 08/13] scripts: get_abi.pl: improve debug logic Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 09/13] scripts: get_abi.pl: Better handle leaves with wildcards Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 10/13] scripts: get_abi.pl: ignore some sysfs nodes earlier Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 11/13] scripts: get_abi.pl: stop check loop earlier when regex is found Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 12/13] scripts: get_abi.pl: precompile what match regexes Mauro Carvalho Chehab
2021-09-23 13:30 ` [PATCH 13/13] scripts: get_abi.pl: ensure that "others" regex will be parsed Mauro Carvalho Chehab
2021-09-23 13:58 ` [PATCH 00/13] get_abi.pl undefined: improve precision and performance Greg Kroah-Hartman
2021-09-23 15:41   ` [PATCH 0/8] (REBASED) " Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 1/8] scripts: get_abi.pl: Fix get_abi.pl search output Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 2/8] scripts: get_abi.pl: call get_leave() a little late Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 3/8] scripts: get_abi.pl: improve debug logic Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 4/8] scripts: get_abi.pl: Better handle leaves with wildcards Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 5/8] scripts: get_abi.pl: ignore some sysfs nodes earlier Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 6/8] scripts: get_abi.pl: stop check loop earlier when regex is found Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 7/8] scripts: get_abi.pl: precompile what match regexes Mauro Carvalho Chehab
2021-09-23 15:41     ` [PATCH 8/8] scripts: get_abi.pl: ensure that "others" regex will be parsed Mauro Carvalho Chehab
2021-09-23 17:13     ` [PATCH 0/8] (REBASED) get_abi.pl undefined: improve precision and performance Greg Kroah-Hartman
2021-09-27  8:55       ` Mauro Carvalho Chehab
2021-09-27  9:23         ` Greg Kroah-Hartman
2021-09-27 13:39           ` Mauro Carvalho Chehab
2021-09-27 15:48             ` Greg Kroah-Hartman
2021-09-28 10:03               ` Mauro Carvalho Chehab
2021-09-28 10:43                 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8612c609e77b1b057172ab13685bdfd3ce37995f.1632402570.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=andrii@kernel.org \
    --cc=anton@enomsg.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ccross@android.com \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=keescook@chromium.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=tony.luck@intel.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.