aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ryhl <[email protected]>2024-02-26 09:44:02 +0000
committerMiguel Ojeda <[email protected]>2024-03-29 18:04:32 +0100
commitd0f0241d8d8b71b3f5fdf0592e6e6b0e44d5d5c0 (patch)
treefd5226dca6c4967d8a100479237cc83670536972
parent4cece764965020c22cff7665b18a012006359095 (diff)
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]>
-rw-r--r--rust/kernel/lib.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index be68d5e567b1..1952a0df0a15 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -92,6 +92,13 @@ impl ThisModule {
pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule {
ThisModule(ptr)
}
+
+ /// Access the raw pointer for this module.
+ ///
+ /// It is up to the user to use it correctly.
+ pub const fn as_ptr(&self) -> *mut bindings::module {
+ self.0
+ }
}
#[cfg(not(any(testlib, test)))]