summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorBenno Lossin <benno.lossin@proton.me>2025-03-08 14:04:43 +0300
committerMiguel Ojeda <ojeda@kernel.org>2025-03-16 23:59:18 +0300
commit5657c3a9faf6c1243cecc9314244c92bfcd1ecad (patch)
tree8999fc069ff6d4bc3d1910edbc375a997110756b /rust/kernel
parent9d29c682f00c3d8dd5727f6a350c4f6ecccc3913 (diff)
downloadlinux-5657c3a9faf6c1243cecc9314244c92bfcd1ecad.tar.xz
rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option<Box<T, A>>`
When making pin-init its own crate, `Zeroable` will no longer be defined by the kernel crate and thus implementing it for `Option<Box<T, A>>` is no longer possible due to the orphan rule. For this reason introduce a new `ZeroableOption` trait that circumvents this problem. Signed-off-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Fiona Behrens <me@kloenk.dev> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Tested-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250308110339.2997091-11-benno.lossin@proton.me Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/alloc/kbox.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
index 9861433559dc..07150c038e3f 100644
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@ -15,7 +15,7 @@ use core::pin::Pin;
use core::ptr::NonNull;
use core::result::Result;
-use crate::init::{InPlaceWrite, Init, PinInit, Zeroable};
+use crate::init::{InPlaceWrite, Init, PinInit, ZeroableOption};
use crate::init_ext::InPlaceInit;
use crate::types::ForeignOwnable;
@@ -104,7 +104,7 @@ pub type KVBox<T> = Box<T, super::allocator::KVmalloc>;
//
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there
// is no problem with a VTABLE pointer being null.
-unsafe impl<T: ?Sized, A: Allocator> Zeroable for Option<Box<T, A>> {}
+unsafe impl<T: ?Sized, A: Allocator> ZeroableOption for Box<T, A> {}
// SAFETY: `Box` is `Send` if `T` is `Send` because the `Box` owns a `T`.
unsafe impl<T, A> Send for Box<T, A>