scripts: kernel-doc: improve parsing for kernel-doc comments syntax
RFC 1/1 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" ininclude/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.
--- scripts/kernel-doc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
scripts/kernel-doc +12 -4
@@ -2110,17 +2110,25 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; my $is_kernel_comment = 0; - if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) { + my $decl_start = qr{\s*\*}; + my $fn_type = qr{\w+\s*\*\s*}; # i.e. pointer declaration type, foo * bar() - desc + my $parenthesis = qr{\(\w*\)}; + my $decl_end = qr{[-:].*}; + if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) { $identifier = $1; - $decl_type = 'function'; - $identifier =~ s/^define\s+//; - $is_kernel_comment = 1; } if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { $decl_type = $1; $identifier = $2; $is_kernel_comment = 1; } + elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || # i.e. foo() + /^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { # i.e. static void foo() - description; or misspelt identifier + $identifier = $1; + $decl_type = 'function'; + $identifier =~ s/^define\s+//; + $is_kernel_comment = 1; + } $identifier =~ s/\s+$//; $state = STATE_BODY;
Signature · 1 line
2.17.1
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Aditya,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on lwn/docs-next]
[also build test WARNING on next-20210414]
[cannot apply to linus/master v5.12-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Aditya-Srivastava/scripts-kernel-doc-improve-parsing-for-kernel-doc-comments-syntax/20210415-032651 base: git://git.lwn.net/linux-2.6 docs-next config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/1ce0c4f2c165f733b954591dbf5b31c834eb0da7 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Aditya-Srivastava/scripts-kernel-doc-improve-parsing-for-kernel-doc-comments-syntax/20210415-032651 git checkout 1ce0c4f2c165f733b954591dbf5b31c834eb0da7 # save the attached .config to linux build tree make W=1 W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
arch/x86/kernel/cpu/sgx/main.c:659: warning: Function parameter or member 'low' not described in 'sgx_calc_section_metric' arch/x86/kernel/cpu/sgx/main.c:659: warning: Function parameter or member 'high' not described in 'sgx_calc_section_metric'
>> arch/x86/kernel/cpu/sgx/main.c:659: warning: expecting prototype for A section metric is concatenated in a way that @low bits 12(). Prototype was for sgx_calc_section_metric() instead
vim +659 arch/x86/kernel/cpu/sgx/main.c
e7e0545299d8cb Sean Christopherson 2020-11-13 652
e7e0545299d8cb Sean Christopherson 2020-11-13 653 /**
e7e0545299d8cb Sean Christopherson 2020-11-13 654 * A section metric is concatenated in a way that @low bits 12-31 define the
e7e0545299d8cb Sean Christopherson 2020-11-13 655 * bits 12-31 of the metric and @high bits 0-19 define the bits 32-51 of the
e7e0545299d8cb Sean Christopherson 2020-11-13 656 * metric.
e7e0545299d8cb Sean Christopherson 2020-11-13 657 */
e7e0545299d8cb Sean Christopherson 2020-11-13 658 static inline u64 __init sgx_calc_section_metric(u64 low, u64 high)
e7e0545299d8cb Sean Christopherson 2020-11-13 @659 {
e7e0545299d8cb Sean Christopherson 2020-11-13 660 return (low & GENMASK_ULL(31, 12)) +
e7e0545299d8cb Sean Christopherson 2020-11-13 661 ((high & GENMASK_ULL(19, 0)) << 32);
e7e0545299d8cb Sean Christopherson 2020-11-13 662 }e7e0545299d8cb Sean Christopherson 2020-11-13 663
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Aditya,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on lwn/docs-next]
[also build test WARNING on next-20210414]
[cannot apply to linus/master v5.12-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Aditya-Srivastava/scripts-kernel-doc-improve-parsing-for-kernel-doc-comments-syntax/20210415-032651 base: git://git.lwn.net/linux-2.6 docs-next config: i386-randconfig-s001-20210414 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-280-g2cd6d34e-dirty # https://github.com/0day-ci/linux/commit/1ce0c4f2c165f733b954591dbf5b31c834eb0da7 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Aditya-Srivastava/scripts-kernel-doc-improve-parsing-for-kernel-doc-comments-syntax/20210415-032651 git checkout 1ce0c4f2c165f733b954591dbf5b31c834eb0da7 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/xen/xenbus/xenbus_client.c:134: warning: Function parameter or member 'will_handle' not described in 'xenbus_watch_path' drivers/xen/xenbus/xenbus_client.c:177: warning: Function parameter or member 'will_handle' not described in 'xenbus_watch_pathfmt' drivers/xen/xenbus/xenbus_client.c:350: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Equivalent to xenbus_dev_fatal(dev, err, fmt, args), but helps
drivers/xen/xenbus/xenbus_client.c:414: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Allocate an event channel for the given xenbus_device, assigning the newly
drivers/xen/xenbus/xenbus_client.c:443: warning: Function parameter or member 'dev' not described in 'xenbus_free_evtchn' drivers/xen/xenbus/xenbus_client.c:443: warning: Function parameter or member 'port' not described in 'xenbus_free_evtchn'
>> drivers/xen/xenbus/xenbus_client.c:443: warning: expecting prototype for Free an existing event channel. Returns 0 on success or(). Prototype was for xenbus_free_evtchn() instead
vim +443 drivers/xen/xenbus/xenbus_client.c
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 437
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 438
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 439 /**
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 440 * Free an existing event channel. Returns 0 on success or -errno on error.
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 441 */
0102e4efda76d0 Yan Yankovskyi 2020-03-23 442 int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port)
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 @443 {
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 444 struct evtchn_close close;
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 445 int err;
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 446
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 447 close.port = port;
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 448
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 449 err = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 450 if (err)
0102e4efda76d0 Yan Yankovskyi 2020-03-23 451 xenbus_dev_error(dev, err, "freeing event channel %u", port);
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 452
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 453 return err;
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 454 }
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 455 EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 456
4bac07c993d034 Jeremy Fitzhardinge 2007-07-17 457 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 55 lines · Aditya Srivastava
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" infs/jbd2/journal.cii) "* dget,
dget_dlock- get a reference to a dentry" ininclude/linux/dcache.hiii) " *
DEFINE_SEQLOCK(sl)- Define a statically allocatedseqlock_t" ininclude/linux/seqlock.hAlso improve identification for non-kerneldoc comments. For e.g.,
i) " * The following functions allow us to read data using a swap map"
inkernel/power/swap.cdoes 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 <[email protected]>Signed-off-by Aditya Srivastava <[email protected]>--- scripts/kernel-doc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)scripts/kernel-doc +5
-4@@ -2110,17 +2110,25 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; my $is_kernel_comment = 0; - if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) { + my $decl_start = qr{\s*\*}; + my $fn_type = qr{\w+\s*\*\s*}; # i.e. pointer declaration type, foo * bar() - desc + my $parenthesis = qr{\(\w*\)}; + my $decl_end = qr{[-:].*}; + if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) { $identifier = $1; - $decl_type = 'function'; - $identifier =~ s/^define\s+//; - $is_kernel_comment = 1; } if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { $decl_type = $1; $identifier = $2; $is_kernel_comment = 1; }
scripts/kernel-doc sub process_name($$) { · line 2134
Quoted 10 lines
scripts/kernel-doc +7
-0+ elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || # i.e. foo() + /^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { # i.e. static void foo() - description; or misspelt identifier + $identifier = $1; + $decl_type = 'function'; + $identifier =~ s/^define\s+//; + $is_kernel_comment = 1; + } $identifier =~ s/\s+$//; $state = STATE_BODY;
Hi
I have generated a diff file for changes in kernel-doc warnings for all the files in the kernel-tree, before and after this patch. It can be found at:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/random/kernel-doc/kernel_doc_comment_syntax_improvement_diff.txt
Thanks
Aditya
Jonathan Corbet
maintainerQuoted 23 lines · Aditya Srivastava
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" infs/jbd2/journal.cii) "* dget,
dget_dlock- get a reference to a dentry" ininclude/linux/dcache.hiii) " *
DEFINE_SEQLOCK(sl)- Define a statically allocatedseqlock_t" ininclude/linux/seqlock.hAlso improve identification for non-kerneldoc comments. For e.g.,
i) " * The following functions allow us to read data using a swap map"
inkernel/power/swap.cdoes 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.
Quoted 6 lines
Suggested-by Jonathan Corbet <[email protected]>Signed-off-by Aditya Srivastava <[email protected]>--- scripts/kernel-doc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
OK, I've applied this, but I have a couple of comments...
scripts/kernel-doc sub process_name($$) { · line 2113
Quoted 10 lines
scripts/kernel-doc +1
-1@@ -2110,17 +2110,25 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; my $is_kernel_comment = 0; - if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) { + my $decl_start = qr{\s*\*};
I appreciate the attempt to make the regexes a bit more comprehensible, but we can do better yet, methinks. This $decl_start is very much like $doc_com defined globally.
It would really help a lot if we could at least take the incredible mass of regexes in this program and boil them down to a smaller, unique set that is used throughout. kernel-doc might still make brains explode, but perhaps the blast radius would be a bit smaller.
scripts/kernel-doc sub process_name($$) { · line 2114
Quoted 1 line
scripts/kernel-doc +1
-0+ my $fn_type = qr{\w+\s*\*\s*}; # i.e. pointer declaration type, foo * bar() - desc
Some of the lines in this change go waaaaay beyond the 80-character limit; please try not to do that. I fixed up the offending comments this time around.
Thanks,
jon