]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: types: require `ForeignOwnable::into_foreign` return non-null
authorAndreas Hindborg <a.hindborg@kernel.org>
Thu, 12 Jun 2025 13:09:44 +0000 (15:09 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 14 Jul 2025 21:55:24 +0000 (23:55 +0200)
The intended implementations of `ForeignOwnable` will not return null
pointers from `into_foreign`, as this would render the implementation of
`try_from_foreign` useless. Current users of `ForeignOwnable` rely on
`into_foreign` returning non-null pointers. So require `into_foreign` to
return non-null pointers.

Suggested-by: Benno Lossin <lossin@kernel.org>
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250612-pointed-to-v3-2-b009006d86a1@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/types.rs

index c156808a78d3cf6589b01c53ba897e7ffdeefa12..63a2559a545f7e73e4c73e9030abe99eef97df7f 100644 (file)
@@ -43,6 +43,7 @@ pub unsafe trait ForeignOwnable: Sized {
     /// # Guarantees
     ///
     /// - Minimum alignment of returned pointer is [`Self::FOREIGN_ALIGN`].
+    /// - The returned pointer is not null.
     ///
     /// [`from_foreign`]: Self::from_foreign
     /// [`try_from_foreign`]: Self::try_from_foreign