From: Benno Lossin Date: Tue, 30 Jul 2024 18:23:04 +0000 (+0000) Subject: rust: types: improve `ForeignOwnable` documentation X-Git-Tag: v6.12-rc1~55^2~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7adcdd572248591c3932e27d98b4a086662d5cbe;p=thirdparty%2Fkernel%2Flinux.git 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 Reviewed-by: Alice Ryhl Link: https://lore.kernel.org/r/20240730182251.1466684-1-benno.lossin@proton.me Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 132ca1113083e..ee7dd1f963efc 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -27,7 +27,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.