public inbox for linux-modules@vger.kernel.org
 help / color / mirror / Atom feed
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>
Subject: [PATCH RFC v3 12/15] rust: phy: make Registration::register() use new ThisModule
Date: Sat, 10 Jan 2026 17:08:10 +0200	[thread overview]
Message-ID: <20260110-this_module_fix-v3-12-97a3d9c14e8b@gmail.com> (raw)
In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com>

Switch `Registration::register()` to take the owning module via the
`ThisModule` abstraction instead of an explicit module parameter.

The function is now generic over `TM: ThisModule`, allowing the module
owner to be resolved at compile time through `TM::OWNER`. This unifies
the way `THIS_MODULE` is passed to Rust abstractions and avoids
threading module pointers manually through the API.

This also removes redundant parameters and prevents accidental
mismatches between the registered drivers and their owning module.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
---
 rust/kernel/net/phy.rs | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 3ca99db5cccf..ef9c4be4f1ad 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -6,8 +6,17 @@
 //!
 //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h).
 
-use crate::{device_id::RawDeviceId, error::*, prelude::*, types::Opaque};
-use core::{marker::PhantomData, ptr::addr_of_mut};
+use crate::{
+    device_id::RawDeviceId,
+    error::*,
+    prelude::*,
+    this_module::ThisModule,
+    types::Opaque, //
+};
+use core::{
+    marker::PhantomData,
+    ptr::addr_of_mut, //
+};
 
 pub mod reg;
 
@@ -648,10 +657,7 @@ unsafe impl Send for Registration {}
 
 impl Registration {
     /// Registers a PHY driver.
-    pub fn register(
-        module: &'static crate::ThisModule,
-        drivers: Pin<&'static mut [DriverVTable]>,
-    ) -> Result<Self> {
+    pub fn register<TM: ThisModule>(drivers: Pin<&'static mut [DriverVTable]>) -> Result<Self> {
         if drivers.is_empty() {
             return Err(code::EINVAL);
         }
@@ -659,7 +665,11 @@ pub fn register(
         // the `drivers` slice are initialized properly. `drivers` will not be moved.
         // So it's just an FFI call.
         to_result(unsafe {
-            bindings::phy_drivers_register(drivers[0].0.get(), drivers.len().try_into()?, module.0)
+            bindings::phy_drivers_register(
+                drivers[0].0.get(),
+                drivers.len().try_into()?,
+                TM::OWNER.as_ptr(),
+            )
         })?;
         // INVARIANT: The `drivers` slice is successfully registered to the kernel via `phy_drivers_register`.
         Ok(Registration { drivers })
@@ -889,12 +899,11 @@ struct Module {
                 [$($crate::net::phy::create_phy_driver::<$driver>()),+];
 
             impl $crate::Module for Module {
-                fn init(module: &'static $crate::ThisModule) -> Result<Self> {
+                fn init(_module: &'static $crate::ThisModule) -> 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 };
-                    let mut reg = $crate::net::phy::Registration::register(
-                        module,
+                    let mut reg = $crate::net::phy::Registration::register::<crate::THIS_MODULE>(
                         ::core::pin::Pin::static_mut(drivers),
                     )?;
                     Ok(Module { _reg: reg })

-- 
2.43.0


  parent reply	other threads:[~2026-01-10 15:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-10 15:07 [PATCH RFC v3 00/15] rust: Reimplement ThisModule to fix ownership problems Kari Argillander
2026-01-10 15:07 ` [PATCH RFC v3 01/15] rust: enable const_refs_to_static feature Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 02/15] rust: add new ThisModule trait and THIS_MODULE impl Kari Argillander
2026-01-14 14:26   ` Petr Pavlu
2026-01-10 15:08 ` [PATCH RFC v3 03/15] rust: miscdevice: fix use after free because missing .owner Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 04/15] rust: block: fix missing owner field in block_device_operations Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 05/15] rust: drm: fix missing owner in file_operations Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 06/15] rust: configfs: use new THIS_MODULE Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 07/15] rust: binder: " Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 08/15] rust: firmware: use THIS_MODULE over LocalModule for name Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 09/15] gpu: nova-core: " Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 10/15] samples: rust: auxiliary: " Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 11/15] rust: driver: make RegistrationOps::register() to use new ThisModule Kari Argillander
2026-01-10 15:08 ` Kari Argillander [this message]
2026-01-10 15:08 ` [PATCH RFC v3 13/15] rust: remove module argument from InPlaceModule::init() Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 14/15] rust: remove kernel::ModuleMetadata Kari Argillander
2026-01-10 15:08 ` [PATCH RFC v3 15/15] rust: remove old version of ThisModule Kari Argillander
2026-01-12 17:56 ` [PATCH RFC v3 00/15] rust: Reimplement ThisModule to fix ownership problems Christophe Leroy (CS GROUP)
2026-01-13 10:33   ` Miguel Ojeda
2026-01-14 14:37 ` Miguel Ojeda
2026-01-27 14:53 ` Gary Guo

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=20260110-this_module_fix-v3-12-97a3d9c14e8b@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=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