summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2026-01-12 17:07:20 +0000
committerMiguel Ojeda <ojeda@kernel.org>2026-01-28 13:44:17 +0100
commit3d5731a6be6a43d8c90d766e1404502c44545241 (patch)
treec258b9655f466118c5d78649bd6b0422b17a0362 /rust
parentc3b416e19eb38a6b8d9a30bc7df1361ac3244464 (diff)
downloadlwn-3d5731a6be6a43d8c90d766e1404502c44545241.tar.gz
lwn-3d5731a6be6a43d8c90d766e1404502c44545241.zip
rust: macros: allow arbitrary types to be used in `module!` macro
Previously this only accepts an identifier, but now with `syn` it is easy to make it accepts any type. Reviewed-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260112170919.1888584-10-gary@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/macros/module.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 43ada49525c9..9e0242d42d51 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -26,7 +26,8 @@ use syn::{
LitStr,
Path,
Result,
- Token, //
+ Token,
+ Type, //
};
use crate::helpers::*;
@@ -370,7 +371,7 @@ impl Parse for Parameter {
}
pub(crate) struct ModuleInfo {
- type_: Ident,
+ type_: Type,
license: AsciiLitStr,
name: AsciiLitStr,
authors: Option<Punctuated<AsciiLitStr, Token![,]>>,
@@ -529,7 +530,6 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
// Double nested modules, since then nobody can access the public items inside.
mod __module_init {
mod __module_init {
- use super::super::#type_;
use pin_init::PinInit;
/// The "Rust loadable module" mark.
@@ -541,7 +541,7 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
#[used(compiler)]
static __IS_RUST_MODULE: () = ();
- static mut __MOD: ::core::mem::MaybeUninit<#type_> =
+ static mut __MOD: ::core::mem::MaybeUninit<super::super::LocalModule> =
::core::mem::MaybeUninit::uninit();
// Loadable modules need to export the `{init,cleanup}_module` identifiers.
@@ -628,8 +628,9 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
///
/// This function must only be called once.
unsafe fn __init() -> ::kernel::ffi::c_int {
- let initer =
- <#type_ as ::kernel::InPlaceModule>::init(&super::super::THIS_MODULE);
+ let initer = <super::super::LocalModule as ::kernel::InPlaceModule>::init(
+ &super::super::THIS_MODULE
+ );
// SAFETY: No data race, since `__MOD` can only be accessed by this module
// and there only `__init` and `__exit` access it. These functions are only
// called once and `__exit` cannot be called before or during `__init`.