Skip to content

Commit d0f0241

Browse files
Darksonnojeda
authored andcommitted
rust: add Module::as_ptr
This allows you to get a raw pointer to THIS_MODULE for use in unsafe code. The Rust Binder RFC uses it when defining fops for the binderfs component [1]. This doesn't really need to go in now - it could go in together with Rust Binder like how it is sent in the Rust Binder RFC. However, the upcoming 1.77.0 release of the Rust compiler introduces a new warning, and applying this patch now will silence that warning. That allows us to avoid adding the #[allow(dead_code)] annotation seen in [2]. Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] Link: https://lore.kernel.org/all/[email protected]/ [2] Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Trevor Gross <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 4cece76 commit d0f0241

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

rust/kernel/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ impl ThisModule {
9292
pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule {
9393
ThisModule(ptr)
9494
}
95+
96+
/// Access the raw pointer for this module.
97+
///
98+
/// It is up to the user to use it correctly.
99+
pub const fn as_ptr(&self) -> *mut bindings::module {
100+
self.0
101+
}
95102
}
96103

97104
#[cfg(not(any(testlib, test)))]

0 commit comments

Comments
 (0)