linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: add `Module::as_ptr`
@ 2024-02-26  9:44 Alice Ryhl
  2024-03-09 13:03 ` Benno Lossin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alice Ryhl @ 2024-02-26  9:44 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg
  Cc: rust-for-linux, linux-kernel, Alice Ryhl

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 <aliceryhl@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 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)))]

---
base-commit: e944171070b65521c0513c01c56174ec8fd7d249
change-id: 20240226-module-as-ptr-08300b88525b

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: add `Module::as_ptr`
  2024-02-26  9:44 [PATCH] rust: add `Module::as_ptr` Alice Ryhl
@ 2024-03-09 13:03 ` Benno Lossin
  2024-03-13 19:09 ` Trevor Gross
  2024-03-29 19:45 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Benno Lossin @ 2024-03-09 13:03 UTC (permalink / raw)
  To: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg
  Cc: rust-for-linux, linux-kernel

On 2/26/24 10:44, Alice Ryhl wrote:
> 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 <aliceryhl@google.com>

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

-- 
Cheers,
Benno


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: add `Module::as_ptr`
  2024-02-26  9:44 [PATCH] rust: add `Module::as_ptr` Alice Ryhl
  2024-03-09 13:03 ` Benno Lossin
@ 2024-03-13 19:09 ` Trevor Gross
  2024-03-29 19:45 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Trevor Gross @ 2024-03-13 19:09 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	rust-for-linux, linux-kernel

On Mon, Feb 26, 2024 at 5:13 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> 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 <aliceryhl@google.com>
> ---

Reviewed-by: Trevor Gross <tmgross@umich.edu>

This exposes a `bindings` type to the user which we don't really do in
many other places, but it makes sense here of course.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: add `Module::as_ptr`
  2024-02-26  9:44 [PATCH] rust: add `Module::as_ptr` Alice Ryhl
  2024-03-09 13:03 ` Benno Lossin
  2024-03-13 19:09 ` Trevor Gross
@ 2024-03-29 19:45 ` Miguel Ojeda
  2 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2024-03-29 19:45 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	rust-for-linux, linux-kernel

On Mon, Feb 26, 2024 at 10:44 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> 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 <aliceryhl@google.com>

Applied to `rust-next` (before the Rust version upgrade) -- thanks everyone!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-29 19:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26  9:44 [PATCH] rust: add `Module::as_ptr` Alice Ryhl
2024-03-09 13:03 ` Benno Lossin
2024-03-13 19:09 ` Trevor Gross
2024-03-29 19:45 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).