* [PATCH] rust: types: improve `ForeignOwnable` documentation
@ 2024-07-30 18:23 Benno Lossin
2024-07-31 8:41 ` Alice Ryhl
2024-08-18 21:32 ` Miguel Ojeda
0 siblings, 2 replies; 3+ messages in thread
From: Benno Lossin @ 2024-07-30 18:23 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl
Cc: rust-for-linux, linux-kernel
There are no guarantees for the pointer returned by `into_foreign`.
This is simply because there is no safety documentation stating any
guarantees. Therefore dereferencing and all other operations for that
pointer are not allowed in a general context (i.e. when the concrete
type implementing the trait is not known).
This might be confusing, therefore add normal documentation to state
that there are no guarantees given for the pointer.
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
---
rust/kernel/types.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index bd189d646adb..0306ec4010a7 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -26,7 +26,10 @@ pub trait ForeignOwnable: Sized {
/// Converts a Rust-owned object to a foreign-owned one.
///
- /// The foreign representation is a pointer to void.
+ /// The foreign representation is a pointer to void. There are no guarantees for this pointer.
+ /// For example, it might be invalid, dangling or pointing to uninitialized memory. Using it in
+ /// any way except for [`ForeignOwnable::from_foreign`], [`ForeignOwnable::borrow`],
+ /// [`ForeignOwnable::try_from_foreign`] can result in undefined behavior.
fn into_foreign(self) -> *const core::ffi::c_void;
/// Borrows a foreign-owned object.
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: types: improve `ForeignOwnable` documentation
2024-07-30 18:23 [PATCH] rust: types: improve `ForeignOwnable` documentation Benno Lossin
@ 2024-07-31 8:41 ` Alice Ryhl
2024-08-18 21:32 ` Miguel Ojeda
1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2024-07-31 8:41 UTC (permalink / raw)
To: Benno Lossin
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, Andreas Hindborg, rust-for-linux,
linux-kernel
On Tue, Jul 30, 2024 at 8:23 PM Benno Lossin <benno.lossin@proton.me> wrote:
>
> There are no guarantees for the pointer returned by `into_foreign`.
> This is simply because there is no safety documentation stating any
> guarantees. Therefore dereferencing and all other operations for that
> pointer are not allowed in a general context (i.e. when the concrete
> type implementing the trait is not known).
> This might be confusing, therefore add normal documentation to state
> that there are no guarantees given for the pointer.
>
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: types: improve `ForeignOwnable` documentation
2024-07-30 18:23 [PATCH] rust: types: improve `ForeignOwnable` documentation Benno Lossin
2024-07-31 8:41 ` Alice Ryhl
@ 2024-08-18 21:32 ` Miguel Ojeda
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2024-08-18 21:32 UTC (permalink / raw)
To: Benno Lossin
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl,
rust-for-linux, linux-kernel
On Tue, Jul 30, 2024 at 8:23 PM Benno Lossin <benno.lossin@proton.me> wrote:
>
> There are no guarantees for the pointer returned by `into_foreign`.
> This is simply because there is no safety documentation stating any
> guarantees. Therefore dereferencing and all other operations for that
> pointer are not allowed in a general context (i.e. when the concrete
> type implementing the trait is not known).
> This might be confusing, therefore add normal documentation to state
> that there are no guarantees given for the pointer.
>
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Applied to `rust-next` -- thanks everyone!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-18 21:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-30 18:23 [PATCH] rust: types: improve `ForeignOwnable` documentation Benno Lossin
2024-07-31 8:41 ` Alice Ryhl
2024-08-18 21:32 ` 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).