Skip to contentSkip to conversation

docs: kdoc: fix struct_group_tagged() parsing regression

PATCH In review Omokefe Emmanuel Onanaroghene 3 participants 3 messages Dec 3 – Dec 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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")

---
v4:
- Rebase onto docs-next; drop the Assisted-by tag.
v3: https://lore.kernel.org/all/[email protected]/
- Previous posting.

 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 ef5879b05308b..4bc36fba5fa8a 100644
@@ -637,7 +637,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 fa380055191c5..52415ef211538 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 709455a4b39c7..21462a1c391b6 100755
@@ -567,6 +567,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 TestUnusedWarnings(GenerateKdocItem):
     """
     Test that the parser itself only emits warnings of discarded entries.
Signature · 1 line
2.43.0
Tested-by on v4 1/1
#1 lore raw
Quoted 7 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.

Works for me, thanks!

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#2 lore raw
In reply to Omokefe Emmanuel Onanaroghene
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] docs: kdoc: struct_group_tagged() member descriptions dropped from output - [Medium] docs: kdoc…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] docs: kdoc: struct_group_tagged() member descriptions dropped from output
- [Medium] docs: kdoc: check_sections() hides missing prefixes on all nested structs
- [Low] docs: kdoc: struct_group_tagged() hides undocumented member warnings
--

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

docs: kdoc: fix struct_group_tagged() parsing regression

This commit updates the struct_group_tagged() kernel-doc transform to preserve the struct tag and member name, relaxes check_sections() to accept unqualified tags matching dotted member suffixes, and adds a unit test based on struct page_pool_params.

Quoted 5 lines
tools/lib/python/kdoc/kdoc_parser.py +0 -0
index ef5879b05308b..4bc36fba5fa8a 100644

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

Quoted 10 lines
tools/lib/python/kdoc/kdoc_parser.py +3 -1
@@ -637,7 +637,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 missing-prefix warnings for all nested structs and unions, not just struct_group_tagged()?

This regresses commit 46d9c16115cf ("scripts/kernel-doc: Detect mismatched inline member documentation tags"): writing @atomic_access instead of @attr.atomic_access on an ordinary nested struct like struct xe_bo no longer warns, while out_struct() drops the description.

It also makes the submember_exact hint path in get_suggestions_hint() unreachable from check_sections().

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

Quoted 13 lines
tools/lib/python/kdoc/xforms_lists.py +1 -1
index fa380055191c5..52415ef211538 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 [1], does rewriting struct_group_tagged() as a named nested struct drop all inner member descriptions from the rendered documentation?

rewrite_struct_members() prefixes inner members with the group name (such as fast.order), so push_parameter() misses the unqualified @order in parameterdescs and marks fast.order undescribed. check_sections() silences the warning without migrating the description.

RestFormat.out_struct() and ManFormat.out_struct() then skip those undescribed entries, omitting 24 documented member descriptions across the four struct_group_tagged() structs in the tree (including struct page_pool_params).

The new TestStructGroupTagged test only asserts that warnings is empty, so it does not catch the dropped descriptions.

[Severity: Low]
Will prefixing inner struct_group_tagged() members also hide genuine missing-description warnings?

KernelDoc.push_parameter() only warns about undocumented members when "." not in param, so dotted names like fast.order now bypass the "not described" check if a member inside struct_group_tagged() lacks kernel-doc.

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

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1