Skip to content

Commit 7adcdd5

Browse files
BennoLossinojeda
authored andcommitted
rust: types: improve ForeignOwnable documentation
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> Link: https://lore.kernel.org/r/20240730182251.1466684-1-benno.lossin@proton.me Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 6c2d0ad commit 7adcdd5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rust/kernel/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ pub trait ForeignOwnable: Sized {
2727

2828
/// Converts a Rust-owned object to a foreign-owned one.
2929
///
30-
/// The foreign representation is a pointer to void.
30+
/// The foreign representation is a pointer to void. There are no guarantees for this pointer.
31+
/// For example, it might be invalid, dangling or pointing to uninitialized memory. Using it in
32+
/// any way except for [`ForeignOwnable::from_foreign`], [`ForeignOwnable::borrow`],
33+
/// [`ForeignOwnable::try_from_foreign`] can result in undefined behavior.
3134
fn into_foreign(self) -> *const core::ffi::c_void;
3235

3336
/// Borrows a foreign-owned object.

0 commit comments

Comments
 (0)