[PATCH] rust: rbtree: fix comments referring to Box instead of KBox

Charalampos Mitrodimas posted 1 patch 9 months ago
rust/kernel/rbtree.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] rust: rbtree: fix comments referring to Box instead of KBox
Posted by Charalampos Mitrodimas 9 months ago
Several safety comments in the RBTree implementation still refer to
"Box::from_raw" and "Box::into_raw", but the code actually uses KBox.
These comments were not updated when the implementation transitioned
from using Box to KBox.

Fixes: 8373147ce496 ("rust: treewide: switch to our kernel `Box` type")
Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
---
 rust/kernel/rbtree.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/rbtree.rs b/rust/kernel/rbtree.rs
index 0d1e75810664e18c0abe851ece2223d203721f79..a7ce512773563150fc2c290c544f20baad6509bf 100644
--- a/rust/kernel/rbtree.rs
+++ b/rust/kernel/rbtree.rs
@@ -1168,12 +1168,12 @@ impl<'a, K, V> RawVacantEntry<'a, K, V> {
     fn insert(self, node: RBTreeNode<K, V>) -> &'a mut V {
         let node = KBox::into_raw(node.node);
 
-        // SAFETY: `node` is valid at least until we call `Box::from_raw`, which only happens when
+        // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when
         // the node is removed or replaced.
         let node_links = unsafe { addr_of_mut!((*node).links) };
 
         // INVARIANT: We are linking in a new node, which is valid. It remains valid because we
-        // "forgot" it with `Box::into_raw`.
+        // "forgot" it with `KBox::into_raw`.
         // SAFETY: The type invariants of `RawVacantEntry` are exactly the safety requirements of `rb_link_node`.
         unsafe { bindings::rb_link_node(node_links, self.parent, self.child_field_of_parent) };
 
@@ -1259,7 +1259,7 @@ pub fn remove(self) -> V {
     fn replace(self, node: RBTreeNode<K, V>) -> RBTreeNode<K, V> {
         let node = KBox::into_raw(node.node);
 
-        // SAFETY: `node` is valid at least until we call `Box::from_raw`, which only happens when
+        // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when
         // the node is removed or replaced.
         let new_node_links = unsafe { addr_of_mut!((*node).links) };
 

---
base-commit: eb88e6bfbc0a975e08a18c39d1138d3e6cdc00a5
change-id: 20250315-rbtree-comment-fixes-99e567449195

Best regards,
-- 
Charalampos Mitrodimas <charmitro@posteo.net>
Re: [PATCH] rust: rbtree: fix comments referring to Box instead of KBox
Posted by Miguel Ojeda 8 months, 4 weeks ago
On Sat, Mar 15, 2025 at 10:48 PM Charalampos Mitrodimas
<charmitro@posteo.net> wrote:
>
> Several safety comments in the RBTree implementation still refer to
> "Box::from_raw" and "Box::into_raw", but the code actually uses KBox.
> These comments were not updated when the implementation transitioned
> from using Box to KBox.
>
> Fixes: 8373147ce496 ("rust: treewide: switch to our kernel `Box` type")
> Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>

Applied to `rust-next` -- thanks everyone!

Cheers,
Miguel
Re: [PATCH] rust: rbtree: fix comments referring to Box instead of KBox
Posted by Alice Ryhl 9 months ago
On Sat, Mar 15, 2025 at 09:48:11PM +0000, Charalampos Mitrodimas wrote:
> Several safety comments in the RBTree implementation still refer to
> "Box::from_raw" and "Box::into_raw", but the code actually uses KBox.
> These comments were not updated when the implementation transitioned
> from using Box to KBox.
> 
> Fixes: 8373147ce496 ("rust: treewide: switch to our kernel `Box` type")
> Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Re: [PATCH] rust: rbtree: fix comments referring to Box instead of KBox
Posted by Benno Lossin 9 months ago
On Sat Mar 15, 2025 at 10:48 PM CET, Charalampos Mitrodimas wrote:
> Several safety comments in the RBTree implementation still refer to
> "Box::from_raw" and "Box::into_raw", but the code actually uses KBox.
> These comments were not updated when the implementation transitioned
> from using Box to KBox.
>
> Fixes: 8373147ce496 ("rust: treewide: switch to our kernel `Box` type")
> Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

---
Cheers,
Benno

> ---
>  rust/kernel/rbtree.rs | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/rbtree.rs b/rust/kernel/rbtree.rs
> index 0d1e75810664e18c0abe851ece2223d203721f79..a7ce512773563150fc2c290c544f20baad6509bf 100644
> --- a/rust/kernel/rbtree.rs
> +++ b/rust/kernel/rbtree.rs
> @@ -1168,12 +1168,12 @@ impl<'a, K, V> RawVacantEntry<'a, K, V> {
>      fn insert(self, node: RBTreeNode<K, V>) -> &'a mut V {
>          let node = KBox::into_raw(node.node);
>  
> -        // SAFETY: `node` is valid at least until we call `Box::from_raw`, which only happens when
> +        // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when
>          // the node is removed or replaced.
>          let node_links = unsafe { addr_of_mut!((*node).links) };
>  
>          // INVARIANT: We are linking in a new node, which is valid. It remains valid because we
> -        // "forgot" it with `Box::into_raw`.
> +        // "forgot" it with `KBox::into_raw`.
>          // SAFETY: The type invariants of `RawVacantEntry` are exactly the safety requirements of `rb_link_node`.
>          unsafe { bindings::rb_link_node(node_links, self.parent, self.child_field_of_parent) };
>  
> @@ -1259,7 +1259,7 @@ pub fn remove(self) -> V {
>      fn replace(self, node: RBTreeNode<K, V>) -> RBTreeNode<K, V> {
>          let node = KBox::into_raw(node.node);
>  
> -        // SAFETY: `node` is valid at least until we call `Box::from_raw`, which only happens when
> +        // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when
>          // the node is removed or replaced.
>          let new_node_links = unsafe { addr_of_mut!((*node).links) };
>  
>
> ---
> base-commit: eb88e6bfbc0a975e08a18c39d1138d3e6cdc00a5
> change-id: 20250315-rbtree-comment-fixes-99e567449195
>
> Best regards,