diff options
author | Danilo Krummrich <dakr@redhat.com> | 2024-06-03 18:06:05 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2024-08-19 02:20:40 +0200 |
commit | 8122493b5aab23b436d55a245ed9618fe7697675 (patch) | |
tree | e574e5fd1dc0193c870ef96228c780fc7078938d /rust | |
parent | 2a1d2157e38bd3cdb8937ce3f100c5d3ee41efcf (diff) |
rust: pass module name to `Module::init`
In a subsequent patch we introduce the `Registration` abstraction used
to register driver structures. Some subsystems require the module name on
driver registration (e.g. PCI in __pci_register_driver()), hence pass
the module name to `Module::init`.
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
Diffstat (limited to 'rust')
-rw-r--r-- | rust/kernel/lib.rs | 14 | ||||
-rw-r--r-- | rust/kernel/net/phy.rs | 2 | ||||
-rw-r--r-- | rust/macros/module.rs | 3 |
3 files changed, 13 insertions, 6 deletions
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index fc4c7f7c03df..79201b86b07e 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -78,7 +78,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(name: &'static str::CStr, module: &'static ThisModule) -> error::Result<Self>; } /// A module that is pinned and initialised in-place. @@ -86,13 +86,19 @@ 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 init::PinInit<Self, error::Error>; + fn init( + name: &'static str::CStr, + module: &'static ThisModule, + ) -> impl init::PinInit<Self, error::Error>; } impl<T: Module> InPlaceModule for T { - fn init(module: &'static ThisModule) -> impl init::PinInit<Self, error::Error> { + fn init( + name: &'static str::CStr, + module: &'static ThisModule, + ) -> impl init::PinInit<Self, error::Error> { let initer = move |slot: *mut Self| { - let m = <Self as Module>::init(module)?; + let m = <Self as Module>::init(name, module)?; // 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 fd40b703d224..ccb2552dc107 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -887,7 +887,7 @@ macro_rules! module_phy_driver { [$($crate::net::phy::create_phy_driver::<$driver>()),+]; impl $crate::Module for Module { - fn init(module: &'static ThisModule) -> Result<Self> { + fn init(_name: &'static CStr, module: &'static 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 }; diff --git a/rust/macros/module.rs b/rust/macros/module.rs index f9be425e0b74..e98e0a4f7afd 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -316,7 +316,8 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { /// /// This function must only be called once. unsafe fn __init() -> core::ffi::c_int {{ - let initer = <{type_} as kernel::InPlaceModule>::init(&super::super::THIS_MODULE); + let initer = <{type_} as kernel::InPlaceModule>::init(kernel::c_str!(\"{name}\"), + &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`. |