Skip to contentSkip to conversation

scripts: kernel-doc: add warning for comment not following kernel-doc syntax

PATCH In review Aditya Srivastava 4 participants 8 messages Mar 29, 2021 – May 24, 2021 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: kernel-doc: add warning for comment not following kernel-doc syntax

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Provide a clearer warning message to the users regarding the same, if the content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
scripts/kernel-doc +13 -4
index cb92d0e1e932..b1d71a7b721f 100755
@@ -2103,15 +2103,17 @@ sub process_name($$) {
 	}
     } elsif (/$doc_decl/o) {
 	$identifier = $1;
-	if (/\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
+	my $is_kernel_comment = 0;
+	if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
 	    $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;
-	} else {
-	    $decl_type = 'function';
-	    $identifier =~ s/^define\s+//;
+	    $is_kernel_comment = 1;
 	}
 	$identifier =~ s/\s+$//;
 
@@ -2133,6 +2135,13 @@ sub process_name($$) {
 	    $declaration_purpose = "";
 	}
 
+	if (!$is_kernel_comment) {
+	    print STDERR "${file}:$.: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n";
+	    print STDERR $_;
+	    ++$warnings;
+	    $state = STATE_NORMAL;
+	}
+
 	if (($declaration_purpose eq "") && $verbose) {
 	    print STDERR "${file}:$.: warning: missing initial short description on line:\n";
 	    print STDERR $_;
Signature · 6 lines
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Aditya,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on lwn/docs-next]
[also build test WARNING on linus/master v5.12-rc5 next-20210329] [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-add-warning-for-comment-not-following-kernel-doc-syntax/20210329-173213
base:   git://git.lwn.net/linux-2.6 docs-next
config: i386-tinyconfig (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/274a7b0af9aa2846ed0a5b2096e07fe76e47fe29
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Aditya-Srivastava/scripts-kernel-doc-add-warning-for-comment-not-following-kernel-doc-syntax/20210329-173213
        git checkout 274a7b0af9aa2846ed0a5b2096e07fe76e47fe29
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> arch/x86/kernel/i8259.c:234: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
    * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
--
>> arch/x86/lib/cmdline.c:17: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

* Find a boolean option (like quiet,noapic,nosmp....)
--
arch/x86/lib/msr.c:40: warning: expecting prototype for Read an MSR with error handling(). Prototype was for msr_read() instead arch/x86/lib/msr.c:58: warning: expecting prototype for Write an MSR with error handling(). Prototype was for msr_write() instead

>> arch/x86/lib/msr.c:91: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

* Set @bit in a MSR @msr.
arch/x86/lib/msr.c:104: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Clear @bit in a MSR @msr.

vim +234 arch/x86/kernel/i8259.c

4305df947ca1fd Thomas Gleixner 2010-09-28  231  
21fd5132b223a1 Pavel Machek    2008-05-21  232  static char irq_trigger[2];
21fd5132b223a1 Pavel Machek    2008-05-21  233  /**
21fd5132b223a1 Pavel Machek    2008-05-21 @234   * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
21fd5132b223a1 Pavel Machek    2008-05-21  235   */
21fd5132b223a1 Pavel Machek    2008-05-21  236  static void restore_ELCR(char *trigger)
21fd5132b223a1 Pavel Machek    2008-05-21  237  {
21fd5132b223a1 Pavel Machek    2008-05-21  238  	outb(trigger[0], 0x4d0);
21fd5132b223a1 Pavel Machek    2008-05-21  239  	outb(trigger[1], 0x4d1);
21fd5132b223a1 Pavel Machek    2008-05-21  240  }
21fd5132b223a1 Pavel Machek    2008-05-21  241  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#2 lore raw
In reply to Aditya Srivastava
Quoted 12 lines · Aditya Srivastava

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Quoted 7 lines

Provide a clearer warning message to the users regarding the same, if the content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

This is definitely a capability we want, but I really don't think that we can turn it on by default - for now. Experience shows that if you create a blizzard of warnings, nobody sees any of them. How many warnings does this add to a full docs build?

For now I think we need a flag to turn this warning on, which perhaps can be set for a W=1 build.

Thanks,

jon
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#6 lore raw
In reply to Aditya Srivastava
Thank you for the patch! Perhaps something to improve:

Hi Aditya,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on lwn/docs-next]
[also build test WARNING on linus/master v5.12-rc5 next-20210329] [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-add-warning-for-comment-not-following-kernel-doc-syntax/20210329-173213
base:   git://git.lwn.net/linux-2.6 docs-next
config: csky-randconfig-r023-20210329 (attached as .config)
compiler: csky-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/274a7b0af9aa2846ed0a5b2096e07fe76e47fe29
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Aditya-Srivastava/scripts-kernel-doc-add-warning-for-comment-not-following-kernel-doc-syntax/20210329-173213 git checkout 274a7b0af9aa2846ed0a5b2096e07fe76e47fe29
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=csky

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/scsi/pm8001/pm8001_ctl.c:313: warning: expecting prototype for pm8001_ctl_sas_address_show(). Prototype was for pm8001_ctl_host_sas_address_show() instead drivers/scsi/pm8001/pm8001_ctl.c:530: warning: expecting prototype for pm8001_ctl_aap_log_show(). Prototype was for pm8001_ctl_iop_log_show() instead

>> drivers/scsi/pm8001/pm8001_ctl.c:559: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

** pm8001_ctl_fatal_log_show - fatal error logging
drivers/scsi/pm8001/pm8001_ctl.c:579: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
** non_fatal_log_show - non fatal error logging
drivers/scsi/pm8001/pm8001_ctl.c:624: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
** pm8001_ctl_gsm_log_show - gsm dump collection

vim +559 drivers/scsi/pm8001/pm8001_ctl.c

dbf9bfe615717d jack wang 2009-10-14 557
d078b5117f18dc Anand Kumar Santhanam 2013-09-04 558 /**

d078b5117f18dc Anand Kumar Santhanam 2013-09-04 @559   ** pm8001_ctl_fatal_log_show - fatal error logging
d078b5117f18dc Anand Kumar Santhanam 2013-09-04  560   ** @cdev:pointer to embedded class device
e1c3e0f8a2ae15 Lee Jones             2020-07-13  561   ** @attr: device attribute
d078b5117f18dc Anand Kumar Santhanam 2013-09-04  562   ** @buf: the buffer returned
d078b5117f18dc Anand Kumar Santhanam 2013-09-04  563   **
d078b5117f18dc Anand Kumar Santhanam 2013-09-04  564   ** A sysfs 'read-only' shost attribute.
d078b5117f18dc Anand Kumar Santhanam 2013-09-04  565   **/

d078b5117f18dc Anand Kumar Santhanam 2013-09-04 566

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Jonathan Corbet
Quoted 22 lines · Jonathan Corbet
Quoted 12 lines · Aditya Srivastava

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Quoted 7 lines

Provide a clearer warning message to the users regarding the same, if the content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Quoted 5 lines

This is definitely a capability we want, but I really don't think that we can turn it on by default - for now. Experience shows that if you create a blizzard of warnings, nobody sees any of them. How many warnings does this add to a full docs build?

Hi Jonathan, here's the diff I have created for the warnings before and after the changes:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/random/kernel-doc/kernel_doc_comment_syntax.txt

Around ~1320 new warnings of this type are added to the kernel tree, and around ~1580 warnings are removed.

Thanks
Aditya

Quoted 6 lines

For now I think we need a flag to turn this warning on, which perhaps can be set for a W=1 build.

Quoted 1 line

Thanks,

jon

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

maintainer
#4 lore raw
Quoted 29 lines · Aditya Srivastava
Quoted 22 lines · Jonathan Corbet
Quoted 12 lines · Aditya Srivastava

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Quoted 7 lines

Provide a clearer warning message to the users regarding the same, if the content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Quoted 5 lines

This is definitely a capability we want, but I really don't think that we can turn it on by default - for now. Experience shows that if you create a blizzard of warnings, nobody sees any of them. How many warnings does this add to a full docs build?

Quoted 6 lines

Hi Jonathan, here's the diff I have created for the warnings before and after the changes:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/random/kernel-doc/kernel_doc_comment_syntax.txt

Around ~1320 new warnings of this type are added to the kernel tree, and around ~1580 warnings are removed.

So I finally got around to looking at this again... How did you generate that file?

I tried applying the patch and doing a normal full htmldocs build and got all of four warnings:

./include/linux/seqlock.h:829: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t
./fs/jbd2/journal.c:1391: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
./fs/jbd2/journal.c:1422: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* journal_t * jbd2_journal_init_inode () - creates a journal which maps to a inode.
./include/linux/dcache.h:309: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* dget, dget_dlock - get a reference to a dentry

Two observations:

- This is not an awful lot of warnings - not the blizzard I had feared. At this level, I think we can just merge the patch and then, hopefully, fix those cases.

- All of the warned-about places are *attempts* to write real kerneldoc comments, they just got the syntax wrong in one way or another. It's probably not worth the effort to try to detect this case - the warning is enough to draw attention to the comment in question.

Thanks,

jon
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#5 lore raw
Quoted 35 lines · Jonathan Corbet
Quoted 33 lines · Aditya Srivastava
Quoted 22 lines · Jonathan Corbet
Quoted 12 lines · Aditya Srivastava

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Quoted 7 lines

Provide a clearer warning message to the users regarding the same, if the content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Quoted 5 lines

This is definitely a capability we want, but I really don't think that we can turn it on by default - for now. Experience shows that if you create a blizzard of warnings, nobody sees any of them. How many warnings does this add to a full docs build?

Hi Jonathan, here's the diff I have created for the warnings before and after the changes:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/random/kernel-doc/kernel_doc_comment_syntax.txt

Quoted 6 lines
Quoted 2 lines

Around ~1320 new warnings of this type are added to the kernel tree, and around ~1580 warnings are removed.

So I finally got around to looking at this again... How did you generate that file?

I ran scripts/kernel-doc -none on all the files in the kernel tree before and after appying the changes, and then generated their diff to find the warnings removed and added.

Quoted 12 lines

I tried applying the patch and doing a normal full htmldocs build and got all of four warnings:

./include/linux/seqlock.h:829: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t
./fs/jbd2/journal.c:1391: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
./fs/jbd2/journal.c:1422: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* journal_t * jbd2_journal_init_inode () - creates a journal which maps to a inode.
./include/linux/dcache.h:309: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* dget, dget_dlock - get a reference to a dentry

I think there should be more warnings. For e.g., running kernel-doc -none ./drivers/usb/mtu3/mtu3.h gives these warnings:

./drivers/usb/mtu3/mtu3.h:75: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst ./drivers/usb/mtu3/mtu3.h:86: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst ./drivers/usb/mtu3/mtu3.h:143: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst

Quoted 11 lines

Two observations:

- This is not an awful lot of warnings - not the blizzard I had feared. At this level, I think we can just merge the patch and then, hopefully, fix those cases.

- All of the warned-about places are *attempts* to write real kerneldoc comments, they just got the syntax wrong in one way or another. It's probably not worth the effort to try to detect this case - the warning is enough to draw attention to the comment in question.

I agree. Above are some of the cases which are not getting detected by this patch.
This may be so as I am only allowing the function syntax as mentioned in the rst file, i.e., "^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$" or ("* foo(\(\))? - description")

I probably need to check for pointers as well and other similar case(s). Maybe I should design a separate check for functions than assigning $decl_type = 'function' in the first check.

What do you think?

Thanks
Aditya

#7 lore raw
In reply to Aditya Srivastava
Quoted 5 lines · Aditya Srivastava

Currently, kernel-doc start parsing the comment as a kernel-doc comment if it starts with '/**', but does not take into account if the content inside the comment too, adheres with the expected format.
This results in unexpected and unclear warnings for the user.

Quoted 8 lines

E.g., running scripts/kernel-doc -none mm/memcontrol.c emits:
"mm/memcontrol.c:961: warning: expecting prototype for do not fallback to current(). Prototype was for get_mem_cgroup_from_current() instead"

Here kernel-doc parses the corresponding comment as a kernel-doc comment and expects prototype for it in the next lines, and as a result causing this warning.

Actually this patch makes things worse by obfuscating the issue. It was way better before.

In the example you give, it's obvious to me that there is descriptive text where the prototype should be.

Now I just get a warning that this "isn't a kernel-doc comment", which a) is not correct and b) could mean anything.

Please consider reverting this patch, as it does the opposite of its intent.

Provide a clearer warning message to the users regarding the same, if the

Quoted 53 lines

content inside the comment does not follow the kernel-doc expected format.

---
 scripts/kernel-doc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
scripts/kernel-doc +8 -4
index cb92d0e1e932..b1d71a7b721f 100755
@@ -2103,15 +2103,17 @@ sub process_name($$) {
        }
     } elsif (/$doc_decl/o) {
        $identifier = $1;
-       if (/\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
+       my $is_kernel_comment = 0;
+       if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) {
            $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;
-       } else {
-           $decl_type = 'function';
-           $identifier =~ s/^define\s+//;
+           $is_kernel_comment = 1;
        }
        $identifier =~ s/\s+$//;
 
@@ -2133,6 +2135,13 @@ sub process_name($$) {
            $declaration_purpose = "";
        }
 
+       if (!$is_kernel_comment) {
+           print STDERR "${file}:$.: warning: This comment starts with

'/**', but isn't a kernel-doc comment. Refer
Documentation/doc-guide/kernel-doc.rst\n";

scripts/kernel-doc +5 -0
+           print STDERR $_;
+           ++$warnings;
+           $state = STATE_NORMAL;
+       }
+
        if (($declaration_purpose eq "") && $verbose) {
            print STDERR "${file}:$.: warning: missing initial short
description on line:\n";
            print STDERR $_;

--
2.17.1

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Senior Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees