[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260107161729.3855851-10-gary@kernel.org>
Date: Wed, 7 Jan 2026 16:15:48 +0000
From: Gary Guo <gary@...nel.org>
To: Miguel Ojeda <ojeda@...nel.org>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Luis Chamberlain <mcgrof@...nel.org>,
Petr Pavlu <petr.pavlu@...e.com>,
Daniel Gomez <da.gomez@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Aaron Tomlin <atomlin@...mlin.com>
Cc: rust-for-linux@...r.kernel.org,
linux-modules@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 09/11] rust: macros: allow arbitrary types to be used in `module!` macro
From: Gary Guo <gary@...yguo.net>
Previously this only accepts an identifier, but now with `syn` it is
easy to make it accepts any type.
Reviewed-by: Benno Lossin <lossin@...nel.org>
Signed-off-by: Gary Guo <gary@...yguo.net>
---
rust/macros/module.rs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index ba345d672839e..31d39764c6926 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -26,7 +26,8 @@
LitStr,
Path,
Result,
- Token, //
+ Token,
+ Type, //
};
use crate::helpers::*;
@@ -376,7 +377,7 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
}
pub(crate) struct ModuleInfo {
- type_: Ident,
+ type_: Type,
license: AsciiLitStr,
name: AsciiLitStr,
authors: Option<Punctuated<AsciiLitStr, Token![,]>>,
@@ -536,7 +537,6 @@ impl ::kernel::ModuleMetadata for #type_ {
// 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.
@@ -548,7 +548,7 @@ mod __module_init {
#[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.
@@ -635,8 +635,9 @@ pub extern "C" fn #ident_exit() {
///
/// 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`.
--
2.51.2
Powered by blists - more mailing lists