From: "Gary Guo" <gary@garyguo.net>
To: "Alvin Sun" <alvin.sun@linux.dev>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Petr Pavlu" <petr.pavlu@suse.com>,
"Daniel Gomez" <da.gomez@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Aaron Tomlin" <atomlin@atomlin.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>,
"Breno Leitao" <leitao@debian.org>,
"Jens Axboe" <axboe@kernel.dk>,
"Dave Ertman" <david.m.ertman@intel.com>,
"Ira Weiny" <ira.weiny@intel.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Igor Korotin" <igor.korotin@linux.dev>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Carlos Llamas" <cmllamas@google.com>
Cc: <rust-for-linux@vger.kernel.org>, <linux-modules@vger.kernel.org>,
<driver-core@lists.linux.dev>, <dri-devel@lists.freedesktop.org>,
<nova-gpu@lists.linux.dev>, <linux-kselftest@vger.kernel.org>,
<kunit-dev@googlegroups.com>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<linux-pci@vger.kernel.org>
Subject: Re: [PATCH v4 3/9] rust: doctest: add LocalModule fallback for #[vtable] ThisModule
Date: Tue, 23 Jun 2026 14:49:58 +0100 [thread overview]
Message-ID: <DJGH6MRDEI4Z.108CPROD89ND5@garyguo.net> (raw)
In-Reply-To: <20260623-fix-fops-owner-v4-3-0daf5f077d5c@linux.dev>
On Tue Jun 23, 2026 at 7:29 AM BST, Alvin Sun wrote:
> Add a `LocalModule` struct with a null-pointer `ModuleMetadata` impl
> in the doctest harness, so that `crate::LocalModule` (auto-inserted
> by `#[vtable]`) resolves correctly when there is no `module!` macro.
>
> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> scripts/rustdoc_test_gen.rs | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
> index ee76e96b41eea..198af4e446c8c 100644
> --- a/scripts/rustdoc_test_gen.rs
> +++ b/scripts/rustdoc_test_gen.rs
> @@ -239,6 +239,22 @@ macro_rules! assert_eq {{
>
> const __LOG_PREFIX: &[u8] = b"rust_doctests_kernel\0";
>
> +/// Dummy module type for doctest context.
> +struct LocalModule;
> +
> +use kernel::{{
> + str::CStr,
> + ModuleMetadata,
> + ThisModule, //
> +}};
> +use core::ptr::null_mut;
> +
> +impl ModuleMetadata for LocalModule {{
> + const NAME: &'static CStr = c"rust_doctests_kernel";
> + // SAFETY: `try_module_get`/`module_put` handle null module pointers gracefully.
> + const THIS_MODULE: ThisModule = unsafe {{ ThisModule::from_ptr(null_mut()) }};
> +}}
We probably a macro for crates that are built-in or are not the main crate of a
multi-crate module, and this would be able to use that mechanism.
But this looks okay for now.
Reviewed-by: Gary Guo <gary@garyguo.net>
> +
> {rust_tests}
> "#
> )
next prev parent reply other threads:[~2026-06-23 13:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 6:29 [PATCH v4 0/9] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
2026-06-23 6:29 ` [PATCH v4 1/9] rust: module: move module types into `module.rs` Alvin Sun
2026-06-23 6:29 ` [PATCH v4 2/9] rust: module: add `THIS_MODULE` const to `ModuleMetadata` trait Alvin Sun
2026-06-23 12:28 ` Andreas Hindborg
2026-06-23 13:46 ` Gary Guo
2026-06-23 6:29 ` [PATCH v4 3/9] rust: doctest: add LocalModule fallback for #[vtable] ThisModule Alvin Sun
2026-06-23 13:49 ` Gary Guo [this message]
2026-06-23 6:29 ` [PATCH v4 4/9] rust: macros: auto-insert OwnerModule in #[vtable] Alvin Sun
2026-06-23 13:50 ` Gary Guo
2026-06-23 6:29 ` [PATCH v4 5/9] rust: drm: set fops.owner from driver module pointer Alvin Sun
2026-06-23 6:29 ` [PATCH v4 6/9] rust: miscdevice: " Alvin Sun
2026-06-23 13:51 ` Gary Guo
2026-06-23 6:29 ` [PATCH v4 7/9] rust: configfs: use `LocalModule` for `THIS_MODULE` Alvin Sun
2026-06-23 13:53 ` Gary Guo
2026-06-23 6:29 ` [PATCH v4 8/9] rust: binder: " Alvin Sun
2026-06-23 13:53 ` Gary Guo
2026-06-23 6:29 ` [PATCH v4 9/9] rust: macros: remove `THIS_MODULE` static from `module!` Alvin Sun
2026-06-23 12:28 ` Andreas Hindborg
2026-06-23 13:53 ` Gary Guo
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=DJGH6MRDEI4Z.108CPROD89ND5@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=alvin.sun@linux.dev \
--cc=arnd@arndb.de \
--cc=arve@android.com \
--cc=atomlin@atomlin.com \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=cmllamas@google.com \
--cc=da.gomez@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=david@davidgow.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=fujita.tomonori@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=igor.korotin@linux.dev \
--cc=ira.weiny@intel.com \
--cc=kunit-dev@googlegroups.com \
--cc=kwilczynski@kernel.org \
--cc=leitao@debian.org \
--cc=leon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mcgrof@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=raemoar63@gmail.com \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=simona@ffwll.ch \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
/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