public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: kbuild <linux-kbuild@vger.kernel.org>,
	lkml <linux-kernel@vger.kernel.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>, Sam Ravnborg <sam@ravnborg.org>
Subject: [PATCH 22/26] kernel-doc: check for extra kernel-doc notations
Date: Sat, 20 Dec 2008 15:31:33 +0100	[thread overview]
Message-ID: <1229783497-19550-22-git-send-email-sam@ravnborg.org> (raw)
In-Reply-To: <20081220142518.GA19390@uranus.ravnborg.org>

From: Randy Dunlap <randy.dunlap@oracle.com>

Add functionality to check for function parameters or structure (or
union/typedef/enum) field members that are described in kernel-doc but
are not part of the expected (declared) parameters or structure.
These generate warnings that are called "Excess" descriptions.

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kernel-doc |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index d27aad7..8bb83a1 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -289,6 +289,8 @@ my %parameterdescs;
 my @parameterlist;
 my %sections;
 my @sectionlist;
+my $sectcheck;
+my $struct_actual;
 
 my $contents = "";
 my $section_default = "Description";	# default section
@@ -378,10 +380,12 @@ sub dump_section {
 #	print STDERR "parameter def '$1' = '$contents'\n";
 	$name = $1;
 	$parameterdescs{$name} = $contents;
+	$sectcheck = $sectcheck . $name . " ";
     } elsif ($name eq "@\.\.\.") {
 #	print STDERR "parameter def '...' = '$contents'\n";
 	$name = "...";
 	$parameterdescs{$name} = $contents;
+	$sectcheck = $sectcheck . $name . " ";
     } else {
 #	print STDERR "other section '$name' = '$contents'\n";
 	if (defined($sections{$name}) && ($sections{$name} ne "")) {
@@ -1405,21 +1409,25 @@ sub dump_union($$) {
 sub dump_struct($$) {
     my $x = shift;
     my $file = shift;
+    my $nested;
 
     if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
 	$declaration_name = $2;
 	my $members = $3;
 
 	# ignore embedded structs or unions
-	$members =~ s/{.*}//g;
+	$members =~ s/({.*})//g;
+	$nested = $1;
 
 	# ignore members marked private:
 	$members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
 	$members =~ s/\/\*.*?private:.*//gos;
 	# strip comments:
 	$members =~ s/\/\*.*?\*\///gos;
+	$nested =~ s/\/\*.*?\*\///gos;
 
 	create_parameterlist($members, ';', $file);
+	check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
 
 	output_declaration($declaration_name,
 			   'struct',
@@ -1505,6 +1513,14 @@ sub dump_typedef($$) {
     }
 }
 
+sub save_struct_actual($) {
+    my $actual = shift;
+
+    # strip all spaces from the actual param so that it looks like one string item
+    $actual =~ s/\s*//g;
+    $struct_actual = $struct_actual . $actual . " ";
+}
+
 sub create_parameterlist($$$) {
     my $args = shift;
     my $splitter = shift;
@@ -1537,6 +1553,7 @@ sub create_parameterlist($$$) {
 	    $param = $1;
 	    $type = $arg;
 	    $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
+	    save_struct_actual($param);
 	    push_parameter($param, $type, $file);
 	} elsif ($arg) {
 	    $arg =~ s/\s*:\s*/:/g;
@@ -1561,14 +1578,17 @@ sub create_parameterlist($$$) {
 
 	    foreach $param (@args) {
 		if ($param =~ m/^(\*+)\s*(.*)/) {
+		    save_struct_actual($2);
 		    push_parameter($2, "$type $1", $file);
 		}
 		elsif ($param =~ m/(.*?):(\d+)/) {
 		    if ($type ne "") { # skip unnamed bit-fields
+			save_struct_actual($1);
 			push_parameter($1, "$type:$2", $file)
 		    }
 		}
 		else {
+		    save_struct_actual($param);
 		    push_parameter($param, $type, $file);
 		}
 	    }
@@ -1634,6 +1654,46 @@ sub push_parameter($$$) {
 	$parametertypes{$param} = $type;
 }
 
+sub check_sections($$$$$$) {
+	my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
+	my @sects = split ' ', $sectcheck;
+	my @prms = split ' ', $prmscheck;
+	my $err;
+	my ($px, $sx);
+	my $prm_clean;		# strip trailing "[array size]" and/or beginning "*"
+
+	foreach $sx (0 .. $#sects) {
+		$err = 1;
+		foreach $px (0 .. $#prms) {
+			$prm_clean = $prms[$px];
+			$prm_clean =~ s/\[.*\]//;
+			$prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//;
+			##$prm_clean =~ s/^\**//;
+			if ($prm_clean eq $sects[$sx]) {
+				$err = 0;
+				last;
+			}
+		}
+		if ($err) {
+			if ($decl_type eq "function") {
+				print STDERR "Warning(${file}:$.): " .
+					"Excess function parameter " .
+					"'$sects[$sx]' " .
+					"description in '$decl_name'\n";
+				++$warnings;
+			} else {
+				if ($nested !~ m/\Q$sects[$sx]\E/) {
+				    print STDERR "Warning(${file}:$.): " .
+					"Excess struct/union/enum/typedef member " .
+					"'$sects[$sx]' " .
+					"description in '$decl_name'\n";
+				    ++$warnings;
+				}
+			}
+		}
+	}
+}
+
 ##
 # takes a function prototype and the name of the current file being
 # processed and spits out all the details stored in the global
@@ -1699,6 +1759,9 @@ sub dump_function($$) {
 	return;
     }
 
+	my $prms = join " ", @parameterlist;
+	check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
+
     output_declaration($declaration_name,
 		       'function',
 		       {'function' => $declaration_name,
@@ -1757,6 +1820,8 @@ sub reset_state {
     @parameterlist = ();
     %sections = ();
     @sectionlist = ();
+    $sectcheck = "";
+    $struct_actual = "";
     $prototype = "";
 
     $state = 0;
-- 
1.6.0.2.GIT


  parent reply	other threads:[~2008-12-20 14:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-20 14:25 kbuild-next content Sam Ravnborg
2008-12-20 14:31 ` [PATCH 01/26] kbuild: fix -I option expansion with O=... builds Sam Ravnborg
2008-12-20 14:31 ` [PATCH 02/26] kbuild: expand -I in KBUILD_CPPFLAGS Sam Ravnborg
2008-12-20 14:31 ` [PATCH 03/26] kbuild: kill output in silent mode of mkcompile_h Sam Ravnborg
2008-12-20 14:31 ` [PATCH 04/26] kbuild: introduce $(kecho) convenience echo Sam Ravnborg
2008-12-20 15:13   ` Vegard Nossum
2008-12-20 19:25     ` Sam Ravnborg
2008-12-20 22:35       ` Vegard Nossum
2008-12-21 21:01   ` Mike Frysinger
2008-12-22 18:49   ` Randy Dunlap
2008-12-20 14:31 ` [PATCH 05/26] kbuild: use KECHO " Sam Ravnborg
2008-12-20 14:31 ` [PATCH 06/26] kbuild: teach mkmakfile to be silent Sam Ravnborg
2008-12-20 14:31 ` [PATCH 07/26] remove bashisms from scripts/extract-ikconfig Sam Ravnborg
2008-12-20 14:31 ` [PATCH 08/26] kbuild: gen_init_cpio expands shell variables in file names Sam Ravnborg
2008-12-20 14:31 ` [PATCH 09/26] kconfig: fix options to check-lxdialog.sh Sam Ravnborg
2008-12-20 14:31 ` [PATCH 10/26] tags and cscope support really belongs in a shell script Sam Ravnborg
2008-12-20 14:31 ` [PATCH 11/26] genksyms: track symbol checksum changes Sam Ravnborg
2008-12-20 14:31 ` [PATCH 12/26] genksyms: allow to ignore " Sam Ravnborg
2008-12-20 14:31 ` [PATCH 13/26] scripts/package: allow custom options to rpm Sam Ravnborg
2008-12-20 14:31 ` [PATCH 14/26] scripts: improve the decodecode script Sam Ravnborg
2008-12-20 14:31 ` [PATCH 15/26] setlocalversion: print correct subversion revision Sam Ravnborg
2008-12-20 14:31 ` [PATCH 16/26] setlocalversion: add git-svn support Sam Ravnborg
2008-12-20 14:31 ` [PATCH 17/26] kbuild: remove TAR_IGNORE Sam Ravnborg
2008-12-20 14:31 ` [PATCH 18/26] kbuild: fix make incompatibility Sam Ravnborg
2008-12-20 14:31 ` [PATCH 19/26] kbuild: fix make tags/cscope Sam Ravnborg
2008-12-20 14:31 ` [PATCH 20/26] kbuild: fix string equality testing in tags.sh Sam Ravnborg
2008-12-20 14:31 ` [PATCH 21/26] kbuild: add headerdep used to detect inclusion cycles in header files Sam Ravnborg
2008-12-20 14:31 ` Sam Ravnborg [this message]
2008-12-20 14:31 ` [PATCH 23/26] kbuild: simplify use of genksyms Sam Ravnborg
2008-12-20 14:31 ` [PATCH 24/26] kbuild: strip generated symbols from *.ko Sam Ravnborg
2008-12-20 14:31 ` [PATCH 25/26] allow stripping of generated symbols under CONFIG_KALLSYMS_ALL Sam Ravnborg
2008-12-20 14:31 ` [PATCH 26/26] kbuild: support switching source directories with O=.. builds Sam Ravnborg
2008-12-20 16:34   ` Andi Kleen
2008-12-20 22:31     ` Sam Ravnborg

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=1229783497-19550-22-git-send-email-sam@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox