From nobody Sun Feb 8 22:58:12 2026 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9EE8339859 for ; Tue, 6 Jan 2026 16:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716009; cv=none; b=dbL81HS0YpPdTeBxztODdDzU9iaqdTVnE9+/dLexXHw8wIRsoDUG8BJteYId+fYxhHk2DW7Vt0pLHHNYU3nb794sj3I8iNmodBVLUoGjajh55BTxGLgdvMDL2v2n75hQlWqwzdlEi9tcJb7Z+DbS12XQtFbD2SSHz671pPoAs2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716009; c=relaxed/simple; bh=ux96t37i0o+XQz9rwL1Xsqa9o9j/lFq1tZiPHrrgcfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TJc95pOO78BjaSPafBBEzPMxyf0VfKyFyvYlibcKImEGL0l8h0xm66OxB8Tms8kJQCxaVScCwUxwA4WwHxsQ466Uk0bn/sDskhbdXmxEd/qRpIUHQV55ioMhP75mv3rXwTTBuaCkfvefoM146k4Cjjn3yE4y+U2iUCQNpXnu7UI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eh/guTD+; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eh/guTD+" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-37b9d8122fdso8854031fa.3 for ; Tue, 06 Jan 2026 08:13:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716005; x=1768320805; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=w/r3EYPU9S+RKnAFCMdSg0qTpeqQzdmOVqZdf6MJWDc=; b=eh/guTD+R/aW9TmdqdN+G0xMr3EUdjtMAMnFOUQAH7peyukSZ9mh4WdV5bTMytjsWy IiT9jafeNhcRsajEdIG/igU7fugiIzm23MwAg/RRiG/rpf6lYFiIc1xFon8fM+GevNR1 FvyH88Zy31lmVIW/tl3Fjo8vfjI7RSJxhC2c33dJ88R3FugEmUfpbn2PxdsD8w/E8ciP 09D1sL3mXlDoP2kuh1R7eEuIsuYny+vugRCJJWoQy81WSG5Er3loWOCSlTlU/LNTFiSt CHQAnAW5cpGCXrLrpI+xhWU1UmN4DOIlbIhCVFh8hncwwYNbVT9PPCHp41j7SOyVbrsE ZAuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716005; x=1768320805; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=w/r3EYPU9S+RKnAFCMdSg0qTpeqQzdmOVqZdf6MJWDc=; b=i3o4WW5EHjI7Q9/Gmez9408NmPOpdul0DJROETb54fij+ji8JZSSqXQt8KwmtUUXIx TAOKrenP690prnq7EXvDFuCWCkPLAh8ItWTO+ipfhNwdpNuOaLOjgjxLECx0XOElocLF wfOPD4IXGw4vXs75ssIzk5TtLVhuFiMuMBpjS4bGoDl4OiGXirnb4nWlT3MVg5zeJh7q GUn5OpE4n7mhEzhpCbvDdjQ+YyE92y192QyzmgFG00z5gOH9O6qmbAAxf6I6iNJQpRTJ jm3WjJ+ew5EGBVFp+Jd6P322P4dPG0DQIv6QKG0M8HlR4Q8CRMimDucVBPy5ys0DXhBK fR0w== X-Forwarded-Encrypted: i=1; AJvYcCVRU/7gUz4OApvn8gEijSuC5qvhsTbVoVmVgAfRHys5GqcPemg/vwXvhSeRIuE0HbM2C136v7P0pIg+ops=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4VVwxdGncoNZNkIPuEm6+BngVM0kkUbr4s16jsd8LKvzQ4/CC 8IY0GKaVPI6vDfyXDcJLtaxIoQBmvNV9HQZaOebseFhGOeFOlgoGoatz X-Gm-Gg: AY/fxX4w0QIM4KtH2LrE4v5hInt7qdkPeRbHx6rDPocWzlzLCrJc+c9SrEIzxdG4qsw s/nhhwBYs/PYi7LBUPAOPgFwVMXUEPr5p6wrA4pIK7INkz6HvoxoMPRN3+iVZJVkZlHkC6BMu1r tsqAHdfWU0ZjcCl9ldO9edLCHDtlE4wX+sGz0Jm11UJhw0kKR3PftLSocOYi4Sqil+xht3AqTof mQrWCHcv6GnOjRb5nsz6rIlqYxiOFYYNPqkT5TqLFbP3o9WcdOb/695FZl+QbPjm4kD5x6RYCSW xnqdDIJM0rKjYlWzeN/2Fq1rGw7iAzODl4/QXI4fmLLHLtYkMwXd8cNyX5MN4mx9iAlJHaX/I+t VZUR6rzzYy9KipC3N/fyT5/3RGwPJwX9Zxo43QxZS1+ihfFTTi7YUtQ2DJJvLX9OEbgfIZqglyM 6bcponIwX9SihPCCzBLmu3Z/uPhX6NxFExDy959RWZSUk06KbbiSHzQlOvNP7hRzSQKyc6GISEr tp+AUtUqfWvXcyD X-Google-Smtp-Source: AGHT+IGYZWam7DBChjxOUl3CONwCvShE1fvapEpMsDYCfGaWU3TWsq5laWGyI8gsXTyWYvUHcv79Mg== X-Received: by 2002:a05:651c:221a:b0:37a:30c5:af1f with SMTP id 38308e7fff4ca-382eaadb376mr11103641fa.40.1767716004648; Tue, 06 Jan 2026 08:13:24 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:24 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:47 +0200 Subject: [PATCH RFC v2 09/11] rust: remove module argument from InPlaceModule::init() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260106-this_module_fix-v2-9-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Kari Argillander , Yuheng Su X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=13585; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=ux96t37i0o+XQz9rwL1Xsqa9o9j/lFq1tZiPHrrgcfg=; b=rRmm6X7wAsFkyggSVE85WlCCByCGyW2Uik6XNWiq6PaAnJGJIKLtaD+udyDf5v2FSjJoAgZ2i VBkL++c3BLZBdhAJJP5v/pWpv3oxK1lhXckuofLLPSz1HXQM5ZA9M3q X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= 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 Closes: https://github.com/Rust-for-Linux/linux/issues/720 Signed-off-by: Kari Argillander --- 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/b= inder/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 { struct BinderModule {} =20 impl kernel::Module for BinderModule { - fn init(_module: &'static kernel::ThisModule) -> Result { + fn init() -> Result { // SAFETY: The module initializer never runs twice, so we only cal= l this once. unsafe { crate::context::CONTEXTS.init() }; =20 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 { } =20 impl kernel::InPlaceModule for NullBlkModule { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Rust null_blk loaded\n"); =20 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}; =20 const BITMAP_LEN: usize =3D 4096 * 8 * 10; @@ -88,7 +87,7 @@ fn find_bit_test() { } =20 impl kernel::Module for Benchmark { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { 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= { +//! fn init() -> impl PinInit { //! pr_info!("Rust configfs sample (init)\n"); //! //! let item_type =3D 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 { } =20 impl $crate::InPlaceModule for DriverModule { - fn init( - _module: &'static $crate::ThisModule - ) -> impl ::pin_init::PinInit { + fn init() -> impl ::pin_init::PinInit { $crate::try_pin_init!(Self { _driver <- $crate::driver::Registration::new::(), }) 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 { +/// # fn init() -> Result { /// # 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; + fn init() -> error::Result; } =20 /// 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; + fn init() -> impl pin_init::PinInit; } =20 impl InPlaceModule for T { - fn init(module: &'static ThisModule) -> impl pin_init::PinInit { + fn init() -> impl pin_init::PinInit { let initer =3D move |slot: *mut Self| { - let m =3D ::init(module)?; + let m =3D ::init()?; =20 // SAFETY: `slot` is valid for write per the contract with `pi= n_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>()),+]; =20 impl $crate::Module for Module { - fn init(_module: &'static $crate::ThisModule) -> Result { + fn init() -> Result { // SAFETY: The anonymous constant guarantees that nobo= dy else can access // the `DRIVERS` static. The array is used only in the= C side. let drivers =3D 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 { +/// fn init() -> Result { /// // 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 { +/// fn init() -> Result { /// // 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 { +/// fn init() -> Result { /// let foo: i32 =3D 42; /// pr_info!("I contain: {}\n", foo); /// pr_info!("i32 param is: {}\n", module_parameters::my_paramete= r.read()); @@ -114,7 +114,7 @@ /// struct MyDeviceDriverModule; /// /// impl kernel::Module for MyDeviceDriverModule { -/// fn init(_module: &'static ThisModule) -> Result { +/// fn init() -> Result { /// 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 =3D - <{type_} as ::kernel::InPlaceModule>::init(&su= per::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 befor= e 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 { } =20 impl kernel::InPlaceModule for RustConfigfs { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Rust configfs sample (init)\n"); =20 // Define a subsystem with the data type `Configuration`, two diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugf= s_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 } =20 impl kernel::Module for RustScopedDebugFs { - fn init(_module: &'static kernel::ThisModule) -> Result { + fn init() -> Result { let base_dir =3D Dir::new(c"rust_scoped_debugfs"); let dyn_dirs =3D base_dir.subdir(c"dynamic"); Ok(Self { diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_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 { } =20 impl InPlaceModule for SampleModule { - fn init(_module: &'static kernel::ThisModule) -> impl PinInit { + fn init() -> impl PinInit { try_pin_init!(Self { _pci_driver <- driver::Registration::new::(), _aux_driver <- driver::Registration::new::(), diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_fa= ux.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 { } =20 impl Module for SampleModule { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { pr_info!("Initialising Rust Faux Device Sample\n"); =20 let reg =3D faux::Registration::new(c"rust-faux-sample-device", No= ne)?; 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 { } =20 impl kernel::Module for RustMinimal { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { 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_devi= ce.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 { } =20 impl kernel::InPlaceModule for RustMiscDeviceModule { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Initialising Rust Misc Device Sample\n"); =20 let options =3D 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) { } =20 impl kernel::Module for RustPrint { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { pr_info!("Rust printing macros sample (init)\n"); =20 pr_emerg!("Emergency message (level 0) without args\n"); --=20 2.43.0