Skip to content

Commit 86ae2e3

Browse files
committed
kernel-doc: support printing exported and non-exported symbols
Currently we use docproc to figure out which symbols are exported, and then docproc calls kernel-doc on specific functions, to get documentation on exported functions. According to git blame and docproc comments, this is due to historical reasons, as functions and their corresponding EXPORT_SYMBOL* may have been in different files. However for more than ten years the recommendation in CodingStyle has been to place the EXPORT_SYMBOL* immediately after the closing function brace line. Additionally, the kernel-doc comments for functions are generally placed above the function definition in the .c files (i.e. where the EXPORT_SYMBOL* is) rather than above the declaration in the .h files. There are some exceptions to this, but AFAICT none of these are included in DocBook documentation using the "!E" docproc directive. Therefore, assuming the EXPORT_SYMBOL* and kernel-doc are with the function definition, kernel-doc can extract the exported vs. not information by making two passes on the input file. Add support for that via the new -export and -internal parameters. Signed-off-by: Jani Nikula <[email protected]>
1 parent 5e64fa9 commit 86ae2e3

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

scripts/kernel-doc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Output format selection (mutually exclusive):
5959
-text Output plain text format.
6060
6161
Output selection (mutually exclusive):
62+
-export Only output documentation for symbols that have been
63+
exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
64+
in the same FILE.
65+
-internal Only output documentation for symbols that have NOT been
66+
exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
67+
in the same FILE.
6268
-function NAME Only output documentation for the given function(s)
6369
or DOC: section title(s). All other functions and DOC:
6470
sections are ignored. May be specified multiple times.
@@ -380,6 +386,7 @@ my $doc_block = $doc_com . 'DOC:\s*(.*)?';
380386
my $doc_split_start = '^\s*/\*\*\s*$';
381387
my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
382388
my $doc_split_end = '^\s*\*/\s*$';
389+
my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
383390

384391
my %constants;
385392
my %parameterdescs;
@@ -444,6 +451,12 @@ while ($ARGV[0] =~ m/^-(.*)/) {
444451
$function_only = 2;
445452
$function = shift @ARGV;
446453
$function_table{$function} = 1;
454+
} elsif ($cmd eq "-export") { # only exported symbols
455+
$function_only = 3;
456+
%function_table = ()
457+
} elsif ($cmd eq "-internal") { # only non-exported symbols
458+
$function_only = 4;
459+
%function_table = ()
447460
} elsif ($cmd eq "-v") {
448461
$verbose = 1;
449462
} elsif (($cmd eq "-h") || ($cmd eq "--help")) {
@@ -1971,8 +1984,10 @@ sub output_declaration {
19711984
my $functype = shift;
19721985
my $func = "output_${functype}_$output_mode";
19731986
if (($function_only==0) ||
1974-
( $function_only == 1 && defined($function_table{$name})) ||
1975-
( $function_only == 2 && !($functype eq "function" && defined($function_table{$name}))))
1987+
( ($function_only == 1 || $function_only == 3) &&
1988+
defined($function_table{$name})) ||
1989+
( ($function_only == 2 || $function_only == 4) &&
1990+
!($functype eq "function" && defined($function_table{$name}))))
19761991
{
19771992
&$func(@_);
19781993
$section_counter++;
@@ -2675,6 +2690,16 @@ sub process_file($) {
26752690
return;
26762691
}
26772692

2693+
# two passes for -export and -internal
2694+
if ($function_only == 3 || $function_only == 4) {
2695+
while (<IN>) {
2696+
if (/$export_symbol/o) {
2697+
$function_table{$2} = 1;
2698+
}
2699+
}
2700+
seek(IN, 0, 0);
2701+
}
2702+
26782703
$. = 1;
26792704

26802705
$section_counter = 0;

0 commit comments

Comments
 (0)