From: Kari Argillander <kari.argillander@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"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>,
"Alexandre Courbot" <acourbot@nvidia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-modules@vger.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>,
Kari Argillander <kari.argillander@gmail.com>,
Yuheng Su <gipsyh.icu@gmail.com>
Subject: [PATCH RFC v2 09/11] rust: remove module argument from InPlaceModule::init()
Date: Tue, 06 Jan 2026 18:11:47 +0200 [thread overview]
Message-ID: <20260106-this_module_fix-v2-9-842ac026f00b@gmail.com> (raw)
In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com>
InPlaceModule::init() has ThisModule argument. However modules always
have THIS_MODULE made by module! macro. So it is unnecessary to pass
same information through this function. End goal is to make idea of
THIS_MODULE simpler. Driver getting this THIS_MODULE from multiple
places is confusing. So let's just stick with THIS_MODULE as that also
works in const context very easily.
Reported-by: Yuheng Su <gipsyh.icu@gmail.com>
Closes: https://github.com/Rust-for-Linux/linux/issues/720
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
---
drivers/android/binder/rust_binder_main.rs | 2 +-
drivers/block/rnull/rnull.rs | 2 +-
lib/find_bit_benchmark_rust.rs | 3 +--
rust/kernel/configfs.rs | 3 +--
rust/kernel/driver.rs | 4 +---
rust/kernel/firmware.rs | 2 +-
rust/kernel/lib.rs | 8 ++++----
rust/kernel/net/phy.rs | 2 +-
rust/kernel/sync/lock/global.rs | 4 ++--
rust/macros/lib.rs | 4 ++--
rust/macros/module.rs | 2 +-
samples/rust/rust_configfs.rs | 2 +-
samples/rust/rust_debugfs_scoped.rs | 2 +-
samples/rust/rust_driver_auxiliary.rs | 2 +-
samples/rust/rust_driver_faux.rs | 2 +-
samples/rust/rust_minimal.rs | 2 +-
samples/rust/rust_misc_device.rs | 2 +-
samples/rust/rust_print_main.rs | 2 +-
18 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
index fc921c0e1116..8b865112e60c 100644
--- a/drivers/android/binder/rust_binder_main.rs
+++ b/drivers/android/binder/rust_binder_main.rs
@@ -291,7 +291,7 @@ fn ptr_align(value: usize) -> Option<usize> {
struct BinderModule {}
impl kernel::Module for BinderModule {
- fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
// SAFETY: The module initializer never runs twice, so we only call this once.
unsafe { crate::context::CONTEXTS.init() };
diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs
index 862369ab9b5c..a9be1b2187f4 100644
--- a/drivers/block/rnull/rnull.rs
+++ b/drivers/block/rnull/rnull.rs
@@ -36,7 +36,7 @@ struct NullBlkModule {
}
impl kernel::InPlaceModule for NullBlkModule {
- fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
+ fn init() -> impl PinInit<Self, Error> {
pr_info!("Rust null_blk loaded\n");
try_pin_init!(Self {
diff --git a/lib/find_bit_benchmark_rust.rs b/lib/find_bit_benchmark_rust.rs
index 6bdc51de2f30..5c231569d887 100644
--- a/lib/find_bit_benchmark_rust.rs
+++ b/lib/find_bit_benchmark_rust.rs
@@ -7,7 +7,6 @@
use kernel::error::{code, Result};
use kernel::prelude::module;
use kernel::time::{Instant, Monotonic};
-use kernel::ThisModule;
use kernel::{pr_cont, pr_err};
const BITMAP_LEN: usize = 4096 * 8 * 10;
@@ -88,7 +87,7 @@ fn find_bit_test() {
}
impl kernel::Module for Benchmark {
- fn init(_module: &'static ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
find_bit_test();
// Return error so test module can be inserted again without rmmod.
Err(code::EINVAL)
diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs
index 908cb98d404f..2af63f7daef2 100644
--- a/rust/kernel/configfs.rs
+++ b/rust/kernel/configfs.rs
@@ -27,7 +27,6 @@
//! use kernel::new_mutex;
//! use kernel::page::PAGE_SIZE;
//! use kernel::sync::Mutex;
-//! use kernel::ThisModule;
//!
//! #[pin_data]
//! struct RustConfigfs {
@@ -36,7 +35,7 @@
//! }
//!
//! impl kernel::InPlaceModule for RustConfigfs {
-//! fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
+//! fn init() -> impl PinInit<Self, Error> {
//! pr_info!("Rust configfs sample (init)\n");
//!
//! let item_type = configfs_attrs! {
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index dc7522c4ebda..de77f95d7fe0 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -201,9 +201,7 @@ struct DriverModule {
}
impl $crate::InPlaceModule for DriverModule {
- fn init(
- _module: &'static $crate::ThisModule
- ) -> impl ::pin_init::PinInit<Self, $crate::error::Error> {
+ fn init() -> impl ::pin_init::PinInit<Self, $crate::error::Error> {
$crate::try_pin_init!(Self {
_driver <- $crate::driver::Registration::new::<crate::THIS_MODULE>(),
})
diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
index 71168d8004e2..11372a8f7be4 100644
--- a/rust/kernel/firmware.rs
+++ b/rust/kernel/firmware.rs
@@ -157,7 +157,7 @@ unsafe impl Sync for Firmware {}
/// # struct MyModule;
/// #
/// # impl kernel::Module for MyModule {
-/// # fn init(_module: &'static ThisModule) -> Result<Self> {
+/// # fn init() -> Result<Self> {
/// # Ok(Self)
/// # }
/// # }
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 2ccd75f68f03..e7bc52a6ad42 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -175,7 +175,7 @@ pub trait Module: Sized + Sync + Send {
/// should do.
///
/// Equivalent to the `module_init` macro in the C API.
- fn init(module: &'static ThisModule) -> error::Result<Self>;
+ fn init() -> error::Result<Self>;
}
/// A module that is pinned and initialised in-place.
@@ -183,13 +183,13 @@ pub trait InPlaceModule: Sync + Send {
/// Creates an initialiser for the module.
///
/// It is called when the module is loaded.
- fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Error>;
+ fn init() -> impl pin_init::PinInit<Self, error::Error>;
}
impl<T: Module> InPlaceModule for T {
- fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Error> {
+ fn init() -> impl pin_init::PinInit<Self, error::Error> {
let initer = move |slot: *mut Self| {
- let m = <Self as Module>::init(module)?;
+ let m = <Self as Module>::init()?;
// SAFETY: `slot` is valid for write per the contract with `pin_init_from_closure`.
unsafe { slot.write(m) };
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index b6c99bf7e97b..7d467d42e951 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -901,7 +901,7 @@ struct Module {
[$($crate::net::phy::create_phy_driver::<$driver>()),+];
impl $crate::Module for Module {
- fn init(_module: &'static $crate::ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
// SAFETY: The anonymous constant guarantees that nobody else can access
// the `DRIVERS` static. The array is used only in the C side.
let drivers = unsafe { &mut DRIVERS };
diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
index eab48108a4ae..7fde464462d1 100644
--- a/rust/kernel/sync/lock/global.rs
+++ b/rust/kernel/sync/lock/global.rs
@@ -203,7 +203,7 @@ pub fn get_mut(&mut self) -> &mut T {
/// }
///
/// impl kernel::Module for MyModule {
-/// fn init(_module: &'static ThisModule) -> Result<Self> {
+/// fn init() -> Result<Self> {
/// // SAFETY: Called exactly once.
/// unsafe { MY_COUNTER.init() };
///
@@ -243,7 +243,7 @@ pub fn get_mut(&mut self) -> &mut T {
/// }
///
/// impl kernel::Module for MyModule {
-/// fn init(_module: &'static ThisModule) -> Result<Self> {
+/// fn init() -> Result<Self> {
/// // SAFETY: Called exactly once.
/// unsafe { MY_MUTEX.init() };
///
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index b38002151871..d22a93696209 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -80,7 +80,7 @@
/// struct MyModule(i32);
///
/// impl kernel::Module for MyModule {
-/// fn init(_module: &'static ThisModule) -> Result<Self> {
+/// fn init() -> Result<Self> {
/// let foo: i32 = 42;
/// pr_info!("I contain: {}\n", foo);
/// pr_info!("i32 param is: {}\n", module_parameters::my_parameter.read());
@@ -114,7 +114,7 @@
/// struct MyDeviceDriverModule;
///
/// impl kernel::Module for MyDeviceDriverModule {
-/// fn init(_module: &'static ThisModule) -> Result<Self> {
+/// fn init() -> Result<Self> {
/// Ok(Self)
/// }
/// }
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 1bcd703735fe..7473a377a3bd 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -490,7 +490,7 @@ mod __module_init {{
/// 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.as_ref());
+ <{type_} as ::kernel::InPlaceModule>::init();
// 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`.
diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs
index 0ccc7553ef39..f34260793677 100644
--- a/samples/rust/rust_configfs.rs
+++ b/samples/rust/rust_configfs.rs
@@ -42,7 +42,7 @@ fn new() -> impl PinInit<Self, Error> {
}
impl kernel::InPlaceModule for RustConfigfs {
- fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
+ fn init() -> impl PinInit<Self, Error> {
pr_info!("Rust configfs sample (init)\n");
// Define a subsystem with the data type `Configuration`, two
diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
index 6a575a15a2c2..75897e02766b 100644
--- a/samples/rust/rust_debugfs_scoped.rs
+++ b/samples/rust/rust_debugfs_scoped.rs
@@ -134,7 +134,7 @@ fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>
}
impl kernel::Module for RustScopedDebugFs {
- fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
let base_dir = Dir::new(c"rust_scoped_debugfs");
let dyn_dirs = base_dir.subdir(c"dynamic");
Ok(Self {
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 28a25e540298..7b729687811d 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -111,7 +111,7 @@ struct SampleModule {
}
impl InPlaceModule for SampleModule {
- fn init(_module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
+ fn init() -> impl PinInit<Self, Error> {
try_pin_init!(Self {
_pci_driver <- driver::Registration::new::<THIS_MODULE>(),
_aux_driver <- driver::Registration::new::<THIS_MODULE>(),
diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs
index 5330b77ea986..2653b2ec3338 100644
--- a/samples/rust/rust_driver_faux.rs
+++ b/samples/rust/rust_driver_faux.rs
@@ -21,7 +21,7 @@ struct SampleModule {
}
impl Module for SampleModule {
- fn init(_module: &'static ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
pr_info!("Initialising Rust Faux Device Sample\n");
let reg = faux::Registration::new(c"rust-faux-sample-device", None)?;
diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs
index 8eb9583571d7..c024f8083499 100644
--- a/samples/rust/rust_minimal.rs
+++ b/samples/rust/rust_minimal.rs
@@ -23,7 +23,7 @@ struct RustMinimal {
}
impl kernel::Module for RustMinimal {
- fn init(_module: &'static ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
pr_info!("Rust minimal sample (init)\n");
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
pr_info!(
diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_device.rs
index 464e3026e6e3..709adf4a6026 100644
--- a/samples/rust/rust_misc_device.rs
+++ b/samples/rust/rust_misc_device.rs
@@ -128,7 +128,7 @@ struct RustMiscDeviceModule {
}
impl kernel::InPlaceModule for RustMiscDeviceModule {
- fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
+ fn init() -> impl PinInit<Self, Error> {
pr_info!("Initialising Rust Misc Device Sample\n");
let options = MiscDeviceOptions {
diff --git a/samples/rust/rust_print_main.rs b/samples/rust/rust_print_main.rs
index 4095c72afeab..de1bf7b80153 100644
--- a/samples/rust/rust_print_main.rs
+++ b/samples/rust/rust_print_main.rs
@@ -59,7 +59,7 @@ fn arc_dyn_print(arc: &Arc<dyn Display>) {
}
impl kernel::Module for RustPrint {
- fn init(_module: &'static ThisModule) -> Result<Self> {
+ fn init() -> Result<Self> {
pr_info!("Rust printing macros sample (init)\n");
pr_emerg!("Emergency message (level 0) without args\n");
--
2.43.0
next prev parent reply other threads:[~2026-01-06 16:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 16:11 [PATCH RFC v2 00/11] rust: Reimplement ThisModule to fix ownership problems Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 01/11] rust: enable const_refs_to_static feature Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 02/11] rust: add new ThisModule trait and THIS_MODULE impl Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 03/11] rust: miscdevice: fix use after free because missing .owner Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 04/11] rust: block: fix missing owner field in block_device_operations Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 05/11] rust: drm: fix missing owner in file_operations Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 06/11] rust: driver: make RegistrationOps::register() to use new ThisModule Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 07/11] rust: phy: make Registration::register() " Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 08/11] rust: binder: use new THIS_MODULE Kari Argillander
2026-01-06 16:11 ` Kari Argillander [this message]
2026-01-06 16:11 ` [PATCH RFC v2 10/11] rust: remove kernel::ModuleMetadata Kari Argillander
2026-01-06 16:11 ` [PATCH RFC v2 11/11] rust: remove old version of ThisModule Kari Argillander
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=20260106-this_module_fix-v2-9-842ac026f00b@gmail.com \
--to=kari.argillander@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=atomlin@atomlin.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=da.gomez@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=gipsyh.icu@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mcgrof@kernel.org \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.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;
as well as URLs for NNTP newsgroup(s).