From: Randy Dunlap <rdunlap@infradead.org>
To: Omokefe Emmanuel Onanaroghene <emmaonana18@gmail.com>,
peterz@infradead.org, elver@google.com, bvanassche@acm.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: corbet@lwn.net, skhan@linuxfoundation.org, mchehab@kernel.org,
aleksandr.loktionov@intel.com, kees@kernel.org,
tudor.ambarus@linaro.org
Subject: Re: [PATCH] docs: kdoc: parse context_lock_struct() as struct declaration
Date: Mon, 28 Sep 2026 10:23:54 -0700 [thread overview]
Message-ID: <c3eeaf92-b1a3-401d-8ece-4f3d513c0b42@infradead.org> (raw)
In-Reply-To: <20260925234054.128477-1-emmaonana18@gmail.com>
On 9/25/26 4:40 PM, Omokefe Emmanuel Onanaroghene wrote:
> kernel-doc fails to parse struct declarations wrapped in
> context_lock_struct(), e.g. struct debugfs_cancellation:
>
> include/linux/debugfs.h:245 ... error: Cannot parse struct or union!
>
> Add a struct transform that expands context_lock_struct() to a plain
> struct declaration, and apply the struct transforms to the whole
> declaration before split_struct_proto(), matching what dump_var() and
> dump_function() already do for their prototypes. The member-only
> transform in dump_struct() is then redundant.
>
> Add a regression test for the debugfs_cancellation declaration.
>
> Fixes: 6e530e2e3119 ("debugfs: Make debugfs_cancellation a context lock struct")
> Signed-off-by: Omokefe Emmanuel Onanaroghene <emmaonana18@gmail.com>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Thanks.
> ---
> tools/lib/python/kdoc/kdoc_parser.py | 11 +++++++----
> tools/lib/python/kdoc/xforms_lists.py | 1 +
> tools/unittests/test_kdoc_parser.py | 26 ++++++++++++++++++++++++++
> 3 files changed, 34 insertions(+), 4 deletions(-)
>
> diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/kdoc_parser.py
> index d9ad1ddc87dd..80d4245acd17 100644
> --- a/tools/lib/python/kdoc/kdoc_parser.py
> +++ b/tools/lib/python/kdoc/kdoc_parser.py
> @@ -831,6 +831,13 @@ class KernelDoc:
> #
> source = source
> proto = trim_private_members(proto)
> +
> + #
> + # Expand macro-based declarations, like context_lock_struct(),
> + # into a plain struct/union declaration before splitting it,
> + # as dump_var() and dump_function() already do.
> + #
> + proto = self.xforms.apply("struct", proto)
> struct_parts = self.split_struct_proto(proto)
> if not struct_parts:
> self.emit_msg(ln, f"{proto} error: Cannot parse struct or union!")
> @@ -841,10 +848,6 @@ class KernelDoc:
> self.emit_msg(ln, f"expecting prototype for {decl_type} {self.entry.identifier}. "
> f"Prototype was for {decl_type} {declaration_name} instead")
> return
> - #
> - # Go through the list of members applying all of our transformations.
> - #
> - members = self.xforms.apply("struct", members)
>
> #
> # Deal with embedded struct and union members, and drop enums entirely.
> diff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py
> index e3dda2fe8a53..9f2c750a811b 100644
> --- a/tools/lib/python/kdoc/xforms_lists.py
> +++ b/tools/lib/python/kdoc/xforms_lists.py
> @@ -62,6 +62,7 @@ class CTransforms:
> (CMatch("struct_group_attr"), r"struct { \3+ };"),
> (CMatch("struct_group_tagged"), r"struct { \3+ };"),
> (CMatch("__struct_group"), r"struct { \4+ };"),
> + (CMatch("context_lock_struct"), r"struct \1"),
> ]
>
> #: Transforms for function prototypes.
> diff --git a/tools/unittests/test_kdoc_parser.py b/tools/unittests/test_kdoc_parser.py
> index c4a76ed13dbc..4baa78ca02b3 100755
> --- a/tools/unittests/test_kdoc_parser.py
> +++ b/tools/unittests/test_kdoc_parser.py
> @@ -418,6 +418,32 @@ class TestSelfValidate(GenerateKdocItem):
> """
> self.run_test(self.SOURCE, [self.DEFAULT.copy()], self.EXPORTS)
>
> +class TestContextLockStruct(GenerateKdocItem):
> + def test_context_lock_struct_declaration(self):
> + source = """
> + /**
> + * struct debugfs_cancellation - cancellation data
> + * @list: internal, for keeping track
> + * @cancel: callback to call
> + * @cancel_data: extra data for the callback to call
> + */
> + context_lock_struct(debugfs_cancellation) {
> + struct list_head list;
> + void (*cancel)(struct dentry *, void *);
> + void *cancel_data;
> + };
> + """
> +
> + 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].name, "debugfs_cancellation")
> + self.assertEqual(entries[0].warnings, [])
> +
> #
> # Class and logic to create dynamic tests from YAML
> #
--
~Randy
next prev parent reply other threads:[~2026-09-28 17:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 23:40 Omokefe Emmanuel Onanaroghene
2026-09-26 0:14 ` Bart Van Assche
2026-09-26 4:56 ` Randy Dunlap
2026-09-26 9:54 ` Omokefe Emmanuel Onanaroghene
2026-09-26 15:16 ` Jonathan Corbet
2026-09-26 16:24 ` Omokefe Emmanuel Onanaroghene
2026-09-26 16:35 ` Jonathan Corbet
2026-09-26 18:41 ` Randy Dunlap
2026-09-28 10:47 ` Marco Elver
2026-09-28 15:18 ` Loktionov, Aleksandr
2026-09-28 17:23 ` Randy Dunlap [this message]
2026-09-29 23:06 ` Jonathan Corbet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c3eeaf92-b1a3-401d-8ece-4f3d513c0b42@infradead.org \
--to=rdunlap@infradead.org \
--cc=aleksandr.loktionov@intel.com \
--cc=bvanassche@acm.org \
--cc=corbet@lwn.net \
--cc=elver@google.com \
--cc=emmaonana18@gmail.com \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=peterz@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=tudor.ambarus@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®