From 7b8e2f408fabfe9bb34a2f6a0bbde064ee446ed9 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Mon, 26 Feb 2024 09:44:02 +0000 Subject: [PATCH] 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/20231101-rust-binder-v1-2-08ba9197f637@google.com/ [1] Link: https://lore.kernel.org/all/20240217002717.57507-1-ojeda@kernel.org/ [2] Signed-off-by: Alice Ryhl Reviewed-by: Benno Lossin Reviewed-by: Trevor Gross Link: https://lore.kernel.org/r/20240226-module-as-ptr-v1-1-83bc89213113@google.com --- rust/kernel/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6cf6105d3ff5bd..43a22c75e7fd25 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -91,6 +91,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)))]