mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 09:20:13 -04:00
rust: doctest: add LocalModule fallback for #[vtable] ThisModule
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. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> Acked-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Alvin Sun <alvin.sun@linux.dev> Link: https://patch.msgid.link/20260811-fix-fops-owner-v10-3-7e71776f9dbe@linux.dev [ Fixed `clippy::undocumented_unsafe_blocks` lint by wrapping with a block. Added interim `#[allow(dead_code)]`. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
@@ -239,6 +239,25 @@ macro_rules! assert_eq {{
|
||||
|
||||
const __LOG_PREFIX: &[u8] = b"rust_doctests_kernel\0";
|
||||
|
||||
/// Dummy module type for doctest context.
|
||||
#[allow(dead_code)]
|
||||
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";
|
||||
const THIS_MODULE: ThisModule = {{
|
||||
// SAFETY: `try_module_get`/`module_put` handle null module pointers gracefully.
|
||||
unsafe {{ ThisModule::from_ptr(null_mut()) }}
|
||||
}};
|
||||
}}
|
||||
|
||||
{rust_tests}
|
||||
"#
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user