Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: avoid `box_uninit_write` feature

Like commit 0903b9e2a46c ("rust: alloc: eschew
`Box<MaybeUninit<T>>::write`"), but for the new `rbtree` and `alloc` code.

That is, `feature(new_uninit)` [1] got partially stabilized [2]
for Rust 1.82.0 (expected to be released on 2024-10-17), but it
did not include `Box<MaybeUninit<T>>::write`, which got split into
`feature(box_uninit_write)` [3].

To avoid relying on a new unstable feature, rewrite the `write` +
`assume_init` pair manually.

Link: https://github.com/rust-lang/rust/issues/63291 [1]
Link: https://github.com/rust-lang/rust/pull/129401 [2]
Link: https://github.com/rust-lang/rust/issues/129397 [3]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Matt Gilbride <mattgilbride@google.com>
Link: https://lore.kernel.org/r/20240904144229.18592-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+12 -11
+4 -2
rust/kernel/alloc/box_ext.rs
··· 26 26 /// use kernel::alloc::{flags, box_ext::BoxExt}; 27 27 /// let value = Box::new([0; 32], flags::GFP_KERNEL)?; 28 28 /// assert_eq!(*value, [0; 32]); 29 - /// let value = Box::drop_contents(value); 29 + /// let mut value = Box::drop_contents(value); 30 30 /// // Now we can re-use `value`: 31 - /// let value = Box::write(value, [1; 32]); 31 + /// value.write([1; 32]); 32 + /// // SAFETY: We just wrote to it. 33 + /// let value = unsafe { value.assume_init() }; 32 34 /// assert_eq!(*value, [1; 32]); 33 35 /// # Ok::<(), Error>(()) 34 36 /// ```
+8 -9
rust/kernel/rbtree.rs
··· 1059 1059 /// Initialises a node reservation. 1060 1060 /// 1061 1061 /// It then becomes an [`RBTreeNode`] that can be inserted into a tree. 1062 - pub fn into_node(self, key: K, value: V) -> RBTreeNode<K, V> { 1063 - let node = Box::write( 1064 - self.node, 1065 - Node { 1066 - key, 1067 - value, 1068 - links: bindings::rb_node::default(), 1069 - }, 1070 - ); 1062 + pub fn into_node(mut self, key: K, value: V) -> RBTreeNode<K, V> { 1063 + self.node.write(Node { 1064 + key, 1065 + value, 1066 + links: bindings::rb_node::default(), 1067 + }); 1068 + // SAFETY: We just wrote to it. 1069 + let node = unsafe { self.node.assume_init() }; 1071 1070 RBTreeNode { node } 1072 1071 } 1073 1072 }