[PATCH v2 12/25] docs: kdoc_parser: ignore context analysis and lock attributes

Mauro Carvalho Chehab posted 25 patches 1 week, 3 days ago
There is a newer version of this series
[PATCH v2 12/25] docs: kdoc_parser: ignore context analysis and lock attributes
Posted by Mauro Carvalho Chehab 1 week, 3 days ago
From: Randy Dunlap <rdunlap@infradead.org>

Drop all context analysis and lock (tracking) attributes to avoid
kernel-doc warnings.

Documentation/core-api/kref:328: ../include/linux/kref.h:72: WARNING: Invalid C declaration: Expected end of definition. [error at 96]
  int kref_put_mutex (struct kref *kref, void (*release)(struct kref *kref), struct mutex *mutex) __cond_acquires(true# mutex)
  ------------------------------------------------------------------------------------------------^
Documentation/core-api/kref:328: ../include/linux/kref.h:94: WARNING: Invalid C declaration: Expected end of definition. [error at 92]
  int kref_put_lock (struct kref *kref, void (*release)(struct kref *kref), spinlock_t *lock) __cond_acquires(true# lock)
  --------------------------------------------------------------------------------------------^

The regex is suggested by Mauro; mine was too greedy. Thanks.
Updated context analysis and lock macros list provided by PeterZ. Thanks.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/all/20260107161548.45530e1c@canb.auug.org.au/
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/kdoc/kdoc_parser.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/kdoc_parser.py
index 21cc4e19a1e8..92b550189988 100644
--- a/tools/lib/python/kdoc/kdoc_parser.py
+++ b/tools/lib/python/kdoc/kdoc_parser.py
@@ -81,6 +81,8 @@ struct_xforms = [
     (KernRe(r'\s*__aligned\s*\([^;]*\)', re.S), ' '),
     (KernRe(r'\s*__counted_by\s*\([^;]*\)', re.S), ' '),
     (KernRe(r'\s*__counted_by_(le|be)\s*\([^;]*\)', re.S), ' '),
+    (KernRe(r'\s*__guarded_by\s*\([^\)]*\)', re.S), ' '),
+    (KernRe(r'\s*__pt_guarded_by\s*\([^\)]*\)', re.S), ' '),
     (KernRe(r'\s*__packed\s*', re.S), ' '),
     (KernRe(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '),
     (KernRe(r'\s*__private', re.S), ' '),
@@ -165,6 +167,16 @@ struct_nested_prefixes = [
 # the start delimiter.
 #
 function_nested_prefixes = [
+    (re.compile(r"__cond_acquires\s*\("), ""),
+    (re.compile(r"__cond_releases\s*\("), ""),
+    (re.compile(r"__acquires\s*\("), ""),
+    (re.compile(r"__releases\s*\("), ""),
+    (re.compile(r"__must_hold\s*\("), ""),
+    (re.compile(r"__must_not_hold\s*\("), ""),
+    (re.compile(r"__must_hold_shared\s*\("), ""),
+    (re.compile(r"__cond_acquires_shared\s*\("), ""),
+    (re.compile(r"__acquires_shared\s*\("), ""),
+    (re.compile(r"__releases_shared\s*\("), ""),
     (re.compile(r"__attribute__\s*\("), ""),
 ]
 
@@ -195,6 +207,7 @@ function_xforms = [
     (KernRe(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +"), ""),
     (KernRe(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +"), ""),
     (KernRe(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)"), r"\1, \2"),
+    (KernRe(r"__no_context_analysis\s*"), ""),
     (KernRe(r"__attribute_const__ +"), ""),
 ]
 
@@ -204,6 +217,8 @@ function_xforms = [
 var_xforms = [
     (KernRe(r"__read_mostly"), ""),
     (KernRe(r"__ro_after_init"), ""),
+    (KernRe(r'\s*__guarded_by\s*\([^\)]*\)', re.S), ""),
+    (KernRe(r'\s*__pt_guarded_by\s*\([^\)]*\)', re.S), ""),
     (KernRe(r"(?://.*)$"), ""),
     (KernRe(r"(?:/\*.*\*/)"), ""),
     (KernRe(r";$"), ""),
-- 
2.52.0
RE: [Intel-wired-lan] [PATCH v2 12/25] docs: kdoc_parser: ignore context analysis and lock attributes
Posted by Loktionov, Aleksandr 1 week, 3 days ago

> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> Of Mauro Carvalho Chehab
> Sent: Wednesday, January 28, 2026 5:50 PM
> To: Jonathan Corbet <corbet@lwn.net>; Linux Doc Mailing List <linux-
> doc@vger.kernel.org>
> Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; Peter Zijlstra
> <peterz@infradead.org>; Randy Dunlap <rdunlap@infradead.org>; Stephen
> Rothwell <sfr@canb.auug.org.au>
> Subject: [Intel-wired-lan] [PATCH v2 12/25] docs: kdoc_parser: ignore
> context analysis and lock attributes
> 
> From: Randy Dunlap <rdunlap@infradead.org>
> 
> Drop all context analysis and lock (tracking) attributes to avoid
> kernel-doc warnings.
> 
> Documentation/core-api/kref:328: ../include/linux/kref.h:72: WARNING:
> Invalid C declaration: Expected end of definition. [error at 96]
>   int kref_put_mutex (struct kref *kref, void (*release)(struct kref
> *kref), struct mutex *mutex) __cond_acquires(true# mutex)
>   --------------------------------------------------------------------
> ----------------------------^
> Documentation/core-api/kref:328: ../include/linux/kref.h:94: WARNING:
> Invalid C declaration: Expected end of definition. [error at 92]
>   int kref_put_lock (struct kref *kref, void (*release)(struct kref
> *kref), spinlock_t *lock) __cond_acquires(true# lock)
>   --------------------------------------------------------------------
> ------------------------^
> 
> The regex is suggested by Mauro; mine was too greedy. Thanks.
> Updated context analysis and lock macros list provided by PeterZ.
> Thanks.
> 
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Closes:
> https://lore.kernel.org/all/20260107161548.45530e1c@canb.auug.org.au/
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  tools/lib/python/kdoc/kdoc_parser.py | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/tools/lib/python/kdoc/kdoc_parser.py
> b/tools/lib/python/kdoc/kdoc_parser.py
> index 21cc4e19a1e8..92b550189988 100644
> --- a/tools/lib/python/kdoc/kdoc_parser.py
> +++ b/tools/lib/python/kdoc/kdoc_parser.py
> @@ -81,6 +81,8 @@ struct_xforms = [
>      (KernRe(r'\s*__aligned\s*\([^;]*\)', re.S), ' '),
>      (KernRe(r'\s*__counted_by\s*\([^;]*\)', re.S), ' '),
>      (KernRe(r'\s*__counted_by_(le|be)\s*\([^;]*\)', re.S), ' '),
> +    (KernRe(r'\s*__guarded_by\s*\([^\)]*\)', re.S), ' '),
> +    (KernRe(r'\s*__pt_guarded_by\s*\([^\)]*\)', re.S), ' '),
>      (KernRe(r'\s*__packed\s*', re.S), ' '),
>      (KernRe(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '),
>      (KernRe(r'\s*__private', re.S), ' '), @@ -165,6 +167,16 @@
> struct_nested_prefixes = [  # the start delimiter.
>  #
>  function_nested_prefixes = [
> +    (re.compile(r"__cond_acquires\s*\("), ""),
> +    (re.compile(r"__cond_releases\s*\("), ""),
> +    (re.compile(r"__acquires\s*\("), ""),
> +    (re.compile(r"__releases\s*\("), ""),
> +    (re.compile(r"__must_hold\s*\("), ""),
> +    (re.compile(r"__must_not_hold\s*\("), ""),
> +    (re.compile(r"__must_hold_shared\s*\("), ""),
> +    (re.compile(r"__cond_acquires_shared\s*\("), ""),
> +    (re.compile(r"__acquires_shared\s*\("), ""),
> +    (re.compile(r"__releases_shared\s*\("), ""),
>      (re.compile(r"__attribute__\s*\("), ""),  ]
> 
> @@ -195,6 +207,7 @@ function_xforms = [
>      (KernRe(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +"),
> ""),
>      (KernRe(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +"), ""),
>      (KernRe(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)"),
> r"\1, \2"),
> +    (KernRe(r"__no_context_analysis\s*"), ""),
>      (KernRe(r"__attribute_const__ +"), ""),  ]
> 
> @@ -204,6 +217,8 @@ function_xforms = [
>  var_xforms = [
>      (KernRe(r"__read_mostly"), ""),
>      (KernRe(r"__ro_after_init"), ""),
> +    (KernRe(r'\s*__guarded_by\s*\([^\)]*\)', re.S), ""),
> +    (KernRe(r'\s*__pt_guarded_by\s*\([^\)]*\)', re.S), ""),
>      (KernRe(r"(?://.*)$"), ""),
>      (KernRe(r"(?:/\*.*\*/)"), ""),
>      (KernRe(r";$"), ""),
> --
> 2.52.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>