Skip to content

Commit f9bbc12

Browse files
AdityaSrivastJonathan Corbet
authored andcommitted
scripts: kernel-doc: improve parsing for kernel-doc comments syntax
Currently kernel-doc does not identify some cases of probable kernel doc comments, for e.g. pointer used as declaration type for identifier, space separated identifier, etc. Some example of these cases in files can be: i)" * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure" in fs/jbd2/journal.c ii) "* dget, dget_dlock - get a reference to a dentry" in include/linux/dcache.h iii) " * DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t" in include/linux/seqlock.h Also improve identification for non-kerneldoc comments. For e.g., i) " * The following functions allow us to read data using a swap map" in kernel/power/swap.c does follow the kernel-doc like syntax, but the content inside does not adheres to the expected format. Improve parsing by adding support for these probable attempts to write kernel-doc comment. Suggested-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/lkml/87mtujktl2.fsf@meer.lwn.net Signed-off-by: Aditya Srivastava <yashsri421@gmail.com> Link: https://lore.kernel.org/r/20210414192529.9080-1-yashsri421@gmail.com [ jc: fixed some line-length issues ] Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 9a18473 commit f9bbc12

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎scripts/kernel-doc‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,17 +2110,28 @@ sub process_name($$) {
21102110
} elsif (/$doc_decl/o) {
21112111
$identifier = $1;
21122112
my $is_kernel_comment = 0;
2113-
if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
2113+
my $decl_start = qr{\s*\*};
2114+
# test for pointer declaration type, foo * bar() - desc
2115+
my $fn_type = qr{\w+\s*\*\s*};
2116+
my $parenthesis = qr{\(\w*\)};
2117+
my $decl_end = qr{[-:].*};
2118+
if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) {
21142119
$identifier = $1;
2115-
$decl_type = 'function';
2116-
$identifier =~ s/^define\s+//;
2117-
$is_kernel_comment = 1;
21182120
}
21192121
if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {
21202122
$decl_type = $1;
21212123
$identifier = $2;
21222124
$is_kernel_comment = 1;
21232125
}
2126+
# Look for foo() or static void foo() - description; or misspelt
2127+
# identifier
2128+
elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||
2129+
/^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {
2130+
$identifier = $1;
2131+
$decl_type = 'function';
2132+
$identifier =~ s/^define\s+//;
2133+
$is_kernel_comment = 1;
2134+
}
21242135
$identifier =~ s/\s+$//;
21252136

21262137
$state = STATE_BODY;

0 commit comments

Comments
 (0)