Skip to contentSkip to conversation

docs: kdoc: fix struct_group_tagged() parsing regression

PATCH Superseded Omokefe Emmanuel Onanaroghene 4 participants 5 messages Nov 29 – Dec 3

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 docs: kdoc: fix struct_group_tagged() parsing regression

kernel-doc reports struct_group_tagged() members as excess because the macro transformation rewrites it to an anonymous struct and drops their member names.

Keep the tag and member name when transforming struct_group_tagged(). The nested members are then recorded as names such as fast.order; accept the existing unqualified @order documentation tag during validation.

Add a regression test based on struct page_pool_params.

Fixes 2f07ddbd5793 ("docs: xforms_lists: better evaluate struct_group macros")
Assisted-by LLM
---
 tools/lib/python/kdoc/kdoc_parser.py  |  4 ++-
 tools/lib/python/kdoc/xforms_lists.py |  2 +-
 tools/unittests/test_kdoc_parser.py   | 37 +++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
tools/lib/python/kdoc/kdoc_parser.py +3 -1
index 80d4245acd172..54b4b7bb32de4 100644
@@ -635,7 +635,9 @@ class KernelDoc:
                 continue
             if param_name.startswith("{unnamed_"):
                 continue
-            if param_name in self.entry.parameterlist:
+            if param_name in self.entry.parameterlist or \
+               any(actual.endswith('.' + param_name)
+                   for actual in self.entry.parameterlist):
                 continue
 
             hint = self.get_suggestions_hint(param_name, self.entry.parameterlist)
tools/lib/python/kdoc/xforms_lists.py +1 -1
index db23fb650ea85..a4c5b111d191f 100644
@@ -62,7 +62,7 @@ class CTransforms:
         #
         (CMatch("struct_group"), r"struct { \2+ };"),
         (CMatch("struct_group_attr"), r"struct { \3+ };"),
-        (CMatch("struct_group_tagged"), r"struct { \3+ };"),
+        (CMatch("struct_group_tagged"), r"struct \1 { \3+ } \2;"),
         (CMatch("__struct_group"), r"struct { \4+ };"),
         (CMatch("context_lock_struct"), r"struct \1"),
     ]
tools/unittests/test_kdoc_parser.py +37 -0
index 4baa78ca02b3f..d31967262d639 100755
@@ -444,6 +444,43 @@ class TestContextLockStruct(GenerateKdocItem):
         self.assertEqual(entries[0].name, "debugfs_cancellation")
         self.assertEqual(entries[0].warnings, [])
 
+
+class TestStructGroupTagged(GenerateKdocItem):
+    def test_nested_struct_group_tagged_members(self):
+        source = """
+            /**
+             * struct page_pool_params - page pool parameters
+             * @fast: Fast path parameters.
+             * @order: Order of pages.
+             * @pool_size: Number of pages.
+             * @slow: Slow path parameters.
+             * @netdev: Net device pointer.
+             * @queue_idx: Queue index.
+             * @flags: Flags.
+             */
+            struct page_pool_params {
+                struct_group_tagged(page_pool_params_fast, fast,
+                                    unsigned int order;
+                                    unsigned int pool_size;
+                );
+                struct_group_tagged(page_pool_params_slow, slow,
+                                    struct net_device *netdev;
+                                    unsigned int queue_idx;
+                                    unsigned int flags;
+                );
+            };
+        """
+
+        kernel_doc = KernelDoc(self.config, "test.c", self.xforms)
+        patcher = patch('builtins.open', new_callable=mock_open,
+                        read_data=dedent(source))
+        with patcher:
+            _, entries = kernel_doc.parse_kdoc()
+
+        self.assertEqual(len(entries), 1)
+        self.assertEqual(entries[0].warnings, [])
+
+
 #
 # Class and logic to create dynamic tests from YAML
 #

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Signature · 1 line
2.43.0
reviewer Acked-by Tested-by on v3 1/1
#1 lore raw
Quoted 8 lines · Omokefe Emmanuel Onanaroghene

kernel-doc reports struct_group_tagged() members as excess because the macro transformation rewrites it to an anonymous struct and drops their member names.

Keep the tag and member name when transforming struct_group_tagged(). The nested members are then recorded as names such as fast.order; accept the existing unqualified @order documentation tag during validation.

Quoted 8 lines

Add a regression test based on struct page_pool_params.

Fixes 2f07ddbd5793 ("docs: xforms_lists: better evaluate struct_group macros")
Assisted-by LLM

WorksForMe. Thanks.

Quoted 85 lines
---
 tools/lib/python/kdoc/kdoc_parser.py  |  4 ++-
 tools/lib/python/kdoc/xforms_lists.py |  2 +-
 tools/unittests/test_kdoc_parser.py   | 37 +++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
tools/lib/python/kdoc/kdoc_parser.py +3 -1
index 80d4245acd172..54b4b7bb32de4 100644
@@ -635,7 +635,9 @@ class KernelDoc:
                 continue
             if param_name.startswith("{unnamed_"):
                 continue
-            if param_name in self.entry.parameterlist:
+            if param_name in self.entry.parameterlist or \
+               any(actual.endswith('.' + param_name)
+                   for actual in self.entry.parameterlist):
                 continue
 
             hint = self.get_suggestions_hint(param_name, self.entry.parameterlist)
tools/lib/python/kdoc/xforms_lists.py +1 -1
index db23fb650ea85..a4c5b111d191f 100644
@@ -62,7 +62,7 @@ class CTransforms:
         #
         (CMatch("struct_group"), r"struct { \2+ };"),
         (CMatch("struct_group_attr"), r"struct { \3+ };"),
-        (CMatch("struct_group_tagged"), r"struct { \3+ };"),
+        (CMatch("struct_group_tagged"), r"struct \1 { \3+ } \2;"),
         (CMatch("__struct_group"), r"struct { \4+ };"),
         (CMatch("context_lock_struct"), r"struct \1"),
     ]
tools/unittests/test_kdoc_parser.py +37 -0
index 4baa78ca02b3f..d31967262d639 100755
@@ -444,6 +444,43 @@ class TestContextLockStruct(GenerateKdocItem):
         self.assertEqual(entries[0].name, "debugfs_cancellation")
         self.assertEqual(entries[0].warnings, [])
 
+
+class TestStructGroupTagged(GenerateKdocItem):
+    def test_nested_struct_group_tagged_members(self):
+        source = """
+            /**
+             * struct page_pool_params - page pool parameters
+             * @fast: Fast path parameters.
+             * @order: Order of pages.
+             * @pool_size: Number of pages.
+             * @slow: Slow path parameters.
+             * @netdev: Net device pointer.
+             * @queue_idx: Queue index.
+             * @flags: Flags.
+             */
+            struct page_pool_params {
+                struct_group_tagged(page_pool_params_fast, fast,
+                                    unsigned int order;
+                                    unsigned int pool_size;
+                );
+                struct_group_tagged(page_pool_params_slow, slow,
+                                    struct net_device *netdev;
+                                    unsigned int queue_idx;
+                                    unsigned int flags;
+                );
+            };
+        """
+
+        kernel_doc = KernelDoc(self.config, "test.c", self.xforms)
+        patcher = patch('builtins.open', new_callable=mock_open,
+                        read_data=dedent(source))
+        with patcher:
+            _, entries = kernel_doc.parse_kdoc()
+
+        self.assertEqual(len(entries), 1)
+        self.assertEqual(entries[0].warnings, [])
+
+
 #
 # Class and logic to create dynamic tests from YAML
 #

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Signature · 1 line
~Randy
#2 lore raw
In reply to Omokefe Emmanuel Onanaroghene
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] docs: kdoc: struct_group_tagged() inner member docs dropped from output - [Medium] docs: kdoc…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] docs: kdoc: struct_group_tagged() inner member docs dropped from output
- [Medium] docs: kdoc: check_sections() suppresses prefix warnings on all nested structs
--

commit 6115678cf3e6e19585bd8d59787433bb0d68c597
Author: Omokefe Emmanuel Onanaroghene <[email protected]>

docs: kdoc: fix struct_group_tagged() parsing regression

This commit preserves the struct tag and member name when transforming struct_group_tagged() in kernel-doc and allows unqualified member tags in check_sections().

Quoted 5 lines
tools/lib/python/kdoc/kdoc_parser.py +0 -0
index 80d4245acd172..54b4b7bb32de4 100644

tools/lib/python/kdoc/kdoc_parser.py class KernelDoc: · line 643

Quoted 10 lines
tools/lib/python/kdoc/kdoc_parser.py +3 -1
@@ -635,7 +635,9 @@ class KernelDoc:
                 continue
             if param_name.startswith("{unnamed_"):
                 continue
-            if param_name in self.entry.parameterlist:
+            if param_name in self.entry.parameterlist or \
+               any(actual.endswith('.' + param_name)
+                   for actual in self.entry.parameterlist):
                 continue
 
             hint = self.get_suggestions_hint(param_name, self.entry.parameterlist)

[Severity: Medium]
As reported by TAKANO Mitsuhiro on v2 [1], does this endswith() check suppress excess-member warnings for ordinary named nested structs and unions that do not use struct_group_tagged()?

When a regular nested member such as foo.bar is documented as @bar:
without its struct prefix, check_sections() now skips it instead of warning and suggesting @foo.bar via get_suggestions_hint().

tools/lib/python/kdoc/xforms_lists.py class CTransforms: · line 68

Quoted 13 lines
tools/lib/python/kdoc/xforms_lists.py +1 -1
index db23fb650ea85..a4c5b111d191f 100644
@@ -62,7 +62,7 @@ class CTransforms:
         #
         (CMatch("struct_group"), r"struct { \2+ };"),
         (CMatch("struct_group_attr"), r"struct { \3+ };"),
-        (CMatch("struct_group_tagged"), r"struct { \3+ };"),
+        (CMatch("struct_group_tagged"), r"struct \1 { \3+ } \2;"),
         (CMatch("__struct_group"), r"struct { \4+ };"),
         (CMatch("context_lock_struct"), r"struct \1"),
     ]

[Severity: Medium]
As reported by TAKANO Mitsuhiro on v2 [2], does rewriting struct_group_tagged() into only a named nested struct cause the inner member descriptions to be dropped from the rendered output?

rewrite_struct_members() prefixes each inner member with the group name (such as fast.order), while dump_section() stores @order: in self.entry.parameterdescs under the unqualified key "order". push_parameter() then fails to find "fast.order" in parameterdescs, sets self.entry.parameterdescs["fast.order"] = self.undescribed, and skips the missing-description warning because "." is in the parameter name.

Because check_sections() only suppresses the excess-member warning for "order" without copying its description to "fast.order", RestFormat.out_struct() and ManFormat.out_struct() see KernelDoc.undescribed for every inner member in parameterlist and omit all of their descriptions from the generated documentation.

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw
In reply to Omokefe Emmanuel Onanaroghene
Quoted 8 lines · Omokefe Emmanuel Onanaroghene

kernel-doc reports struct_group_tagged() members as excess because the macro transformation rewrites it to an anonymous struct and drops their member names.

Keep the tag and member name when transforming struct_group_tagged(). The nested members are then recorded as names such as fast.order; accept the existing unqualified @order documentation tag during validation.

Quoted 6 lines

Add a regression test based on struct page_pool_params.

Fixes 2f07ddbd5793 ("docs: xforms_lists: better evaluate struct_group macros")
Assisted-by LLM

That tag is no longer needed.

Quoted 2 lines

This patch is not even close to applying to docs-next; you appear to have built it against 7.4-rc4, which is not helpful. Please resubmit based on docs-next.

Thanks,

jon

#4 lore raw
Quoted 1 line · On Wed, 02 Dec 2026 12:47:56 -0700 Jonathan Corbet wrote:

That tag is no longer needed.

Dropped.

Quoted 3 lines

This patch is not even close to applying to docs-next; you appear to have built it against 7.4-rc4, which is not helpful. Please resubmit based on docs-next.

Done in v4
https://lore.kernel.org/all/[email protected]/

Thanks,

Omokefe