History

scripts: kernel-doc: validate kernel-doc markup with the actual names

Kernel-doc currently expects that the kernel-doc markup to come just before the function/enum/struct/union/typedef prototype. Yet, if it find things like: /** * refcount_add - add a value to a refcount * @i: the value to add to the refcount * @r: the refcount */ static inline void __refcount_add(int i, refcount_t *r, int *oldp); static inline void refcount_add(int i, refcount_t *r); Kernel-doc will do the wrong thing: foobar.h:6: warning: Function parameter or member 'oldp' not described in '__refcount_add' .. c:function:: void __refcount_add (int i, refcount_t *r, int *oldp) add a value to a refcount **Parameters** ``int i`` the value to add to the refcount ``refcount_t *r`` the refcount ``int *oldp`` *undescribed* Basically, it will document "__refcount_add" with the kernel-doc markup for refcount_add. If both functions have the same arguments, this won't even produce any warning! Add a logic to check if the kernel-doc identifier matches the actual name of the C function or data structure that will be documented.

Mauro Carvalho Chehab committed 5 years ago

Commit 52042e21 parent 96c0f7c1 file · +46 −16Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/kernel-doc+46−16
@@ -382,6 +382,9 @@ my $inline_doc_state; · 381 unmodified lines
382382 # 'function', 'struct', 'union', 'enum', 'typedef'
383383 my $decl_type;
384384
385+# Name of the kernel-doc identifier for non-DOC markups
386+my $identifier;
387+
385388 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
386389 my $doc_end = '\*/';
387390 my $doc_com = '\s*\*\s*';
@@ -1203,6 +1206,11 @@ sub dump_struct($$) { · 815 unmodified lines
12031206 $declaration_name = $2;
12041207 my $members = $3;
12051208
1209+ if ($identifier ne $declaration_name) {
1210+ print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n";
1211+ return;
1212+ }
1213+
12061214 # ignore members marked private:
12071215 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
12081216 $members =~ s/\/\*\s*private:.*//gosi;
@@ -1391,6 +1399,11 @@ sub dump_enum($$) { · 182 unmodified lines
13911399 }
13921400
13931401 if ($members) {
1402+ if ($identifier ne $declaration_name) {
1403+ print STDERR "${file}:$.: warning: expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n";
1404+ return;
1405+ }
1406+
13941407 my %_members;
13951408
13961409 $members =~ s/\s+$//;
@@ -1451,6 +1464,11 @@ sub dump_typedef($$) { · 54 unmodified lines
14511464 my $args = $3;
14521465 $return_type =~ s/^\s+//;
14531466
1467+ if ($identifier ne $declaration_name) {
1468+ print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n";
1469+ return;
1470+ }
1471+
14541472 create_parameterlist($args, ',', $file, $declaration_name);
14551473
14561474 output_declaration($declaration_name,
@@ -1477,6 +1495,11 @@ sub dump_typedef($$) { · 20 unmodified lines
14771495 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
14781496 $declaration_name = $1;
14791497
1498+ if ($identifier ne $declaration_name) {
1499+ print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n";
1500+ return;
1501+ }
1502+
14801503 output_declaration($declaration_name,
14811504 'typedef',
14821505 {'typedef' => $declaration_name,
@@ -1796,6 +1819,11 @@ sub dump_function($$) { · 313 unmodified lines
17961819 return;
17971820 }
17981821
1822+ if ($identifier ne $declaration_name) {
1823+ print STDERR "${file}:$.: warning: expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n";
1824+ return;
1825+ }
1826+
17991827 my $prms = join " ", @parameterlist;
18001828 check_sections($file, $declaration_name, "function", $sectcheck, $prms);
18011829
@@ -1878,6 +1906,7 @@ sub tracepoint_munge($) { · 76 unmodified lines
18781906 "$prototype\n";
18791907 } else {
18801908 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1909+ $identifier = "trace_$identifier";
18811910 }
18821911 }
18831912
@@ -2041,7 +2070,6 @@ sub process_normal() { · 157 unmodified lines
20412070 #
20422071 sub process_name($$) {
20432072 my $file = shift;
2044− my $identifier;
20452073 my $descr;
20462074
20472075 if (/$doc_block/o) {
@@ -2054,12 +2082,19 @@ sub process_name($$) { · 6 unmodified lines
20542082 } else {
20552083 $section = $1;
20562084 }
2057− }
2058− elsif (/$doc_decl/o) {
2085+ } elsif (/$doc_decl/o) {
20592086 $identifier = $1;
2060− if (/\s*([\w\s]+?)(\(\))?\s*-/) {
2087+ if (/\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
20612088 $identifier = $1;
20622089 }
2090+ if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {
2091+ $decl_type = $1;
2092+ $identifier = $2;
2093+ } else {
2094+ $decl_type = 'function';
2095+ $identifier =~ s/^define\s+//;
2096+ }
2097+ $identifier =~ s/\s+$//;
20632098
20642099 $state = STATE_BODY;
20652100 # if there's no @param blocks need to set up default section
@@ -2067,7 +2102,7 @@ sub process_name($$) { · 1 unmodified line
20672102 $contents = "";
20682103 $section = $section_default;
20692104 $new_start_line = $. + 1;
2070− if (/-(.*)/) {
2105+ if (/[-:](.*)/) {
20712106 # strip leading/trailing/multiple spaces
20722107 $descr= $1;
20732108 $descr =~ s/^\s*//;
@@ -2085,20 +2120,15 @@ sub process_name($$) { · 11 unmodified lines
20852120 ++$warnings;
20862121 }
20872122
2088− if ($identifier =~ m/^struct\b/) {
2089− $decl_type = 'struct';
2090− } elsif ($identifier =~ m/^union\b/) {
2091− $decl_type = 'union';
2092− } elsif ($identifier =~ m/^enum\b/) {
2093− $decl_type = 'enum';
2094− } elsif ($identifier =~ m/^typedef\b/) {
2095− $decl_type = 'typedef';
2096− } else {
2097− $decl_type = 'function';
2123+ if ($identifier eq "") {
2124+ print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n";
2125+ print STDERR $_;
2126+ ++$warnings;
2127+ $state = STATE_NORMAL;
20982128 }
20992129
21002130 if ($verbose) {
2101− print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
2131+ print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n";
21022132 }
21032133 } else {
21042134 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t