diff mbox series

scripts: kernel-doc: Ignore __alloc_size() attribute

Message ID 20211011180650.3603988-1-keescook@chromium.org (mailing list archive)
State New
Headers show
Series scripts: kernel-doc: Ignore __alloc_size() attribute | expand

Commit Message

Kees Cook Oct. 11, 2021, 6:06 p.m. UTC
Fixes "Compiler Attributes: add __alloc_size() for better bounds checking"
so that the __alloc_size() macro is ignored for function prototypes when
generating kerndoc. Avoids warnings like:

./include/linux/slab.h:662: warning: Function parameter or member '1' not described in '__alloc_size'
./include/linux/slab.h:662: warning: Function parameter or member '2' not described in '__alloc_size'
./include/linux/slab.h:662: warning: expecting prototype for kcalloc().  Prototype was for __alloc_size() instead

Suggested-by: Matthew Wilcox <willy@infradead.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 scripts/kernel-doc | 1 +
 1 file changed, 1 insertion(+)

Comments

Joe Perches Oct. 11, 2021, 6:23 p.m. UTC | #1
On Mon, 2021-10-11 at 11:06 -0700, Kees Cook wrote:
> Fixes "Compiler Attributes: add __alloc_size() for better bounds checking"
> so that the __alloc_size() macro is ignored for function prototypes when
> generating kerndoc. Avoids warnings like:
> 
> ./include/linux/slab.h:662: warning: Function parameter or member '1' not described in '__alloc_size'
> ./include/linux/slab.h:662: warning: Function parameter or member '2' not described in '__alloc_size'
> ./include/linux/slab.h:662: warning: expecting prototype for kcalloc().  Prototype was for __alloc_size() instead
[]
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
[]
> @@ -1789,6 +1789,7 @@ sub dump_function($$) {
>      $prototype =~ s/__weak +//;
>      $prototype =~ s/__sched +//;
>      $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
> +    $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//;
>      my $define = $prototype =~ s/^#\s*define\s+//; #ak added
>      $prototype =~ s/__attribute_const__ +//;
>      $prototype =~ s/__attribute__\s*\(\(

Perhaps all this would be more intelligible and a bit more future-proof
using a regex that consumes all the various __<foo> prefixed attributes.

Maybe:

	my $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
	$prototype =~ s/\b__\w+\s*(?:$balanced_parens)?\s*//g;
Jonathan Corbet Oct. 12, 2021, 8:23 p.m. UTC | #2
Kees Cook <keescook@chromium.org> writes:

> Fixes "Compiler Attributes: add __alloc_size() for better bounds checking"
> so that the __alloc_size() macro is ignored for function prototypes when
> generating kerndoc. Avoids warnings like:
>
> ./include/linux/slab.h:662: warning: Function parameter or member '1' not described in '__alloc_size'
> ./include/linux/slab.h:662: warning: Function parameter or member '2' not described in '__alloc_size'
> ./include/linux/slab.h:662: warning: expecting prototype for kcalloc().  Prototype was for __alloc_size() instead
>
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  scripts/kernel-doc | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks.

jon
diff mbox series

Patch

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index cfcb60737957..c123bac28f7a 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1789,6 +1789,7 @@  sub dump_function($$) {
     $prototype =~ s/__weak +//;
     $prototype =~ s/__sched +//;
     $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
+    $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//;
     my $define = $prototype =~ s/^#\s*define\s+//; #ak added
     $prototype =~ s/__attribute_const__ +//;
     $prototype =~ s/__attribute__\s*\(\(