linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute
@ 2021-10-11 18:06 Kees Cook
  2021-10-11 18:23 ` Joe Perches
  2021-10-12 20:23 ` Jonathan Corbet
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2021-10-11 18:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kees Cook, Matthew Wilcox, Stephen Rothwell, Joe Perches,
	Jonathan Corbet, linux-mm, linux-kernel, linux-doc,
	linux-hardening

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(+)

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*\(\(
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute
  2021-10-11 18:06 [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute Kees Cook
@ 2021-10-11 18:23 ` Joe Perches
  2021-10-12 20:23 ` Jonathan Corbet
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2021-10-11 18:23 UTC (permalink / raw)
  To: Kees Cook, Andrew Morton
  Cc: Matthew Wilcox, Stephen Rothwell, Jonathan Corbet, linux-mm,
	linux-kernel, linux-doc, linux-hardening

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;





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute
  2021-10-11 18:06 [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute Kees Cook
  2021-10-11 18:23 ` Joe Perches
@ 2021-10-12 20:23 ` Jonathan Corbet
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Corbet @ 2021-10-12 20:23 UTC (permalink / raw)
  To: Kees Cook, Andrew Morton
  Cc: Kees Cook, Matthew Wilcox, Stephen Rothwell, Joe Perches,
	linux-mm, linux-kernel, linux-doc, linux-hardening

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-12 20:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 18:06 [PATCH] scripts: kernel-doc: Ignore __alloc_size() attribute Kees Cook
2021-10-11 18:23 ` Joe Perches
2021-10-12 20:23 ` Jonathan Corbet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).