]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: rbtree: reduce unsafe blocks on pointer derefs
authorOnur Özkan <work@onurozkan.dev>
Thu, 13 Nov 2025 14:45:47 +0000 (17:45 +0300)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 19 Jan 2026 08:38:10 +0000 (09:38 +0100)
commit2ad6c5cdc89acfefb01b84afa5e55262c40d6fec
tree40197866451ae5c81e3a7238752c3dadea6d4c71
parent6c37b6841a92714eba4a7b7f823aea801da4e09f
rust: rbtree: reduce unsafe blocks on pointer derefs

Refactors parts of the get() and find_best_match()
traversal logic to minimize the scope of unsafe blocks
and avoid duplicating same safety comments.

One of the removed comments was also misleading:

    // SAFETY: `node` is a non-null node...
    Ordering::Equal => return Some(unsafe { &(*this).value }),

as `node` should have been `this`.

No functional changes intended; this is purely a safety
improvement that reduces the amount of unsafe blocks
while keeping all invariants intact.

[ Alice writes:

    "One consequence of creating a &_ to the bindings::rb_node struct means
    that we assert immutability for the entire struct and not just the
    rb_left/rb_right fields, but I have verified that this is ok."

      - Miguel ]

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Charalampos Mitrodimas <charmitro@posteo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251113144547.502-1-work@onurozkan.dev
[ Reworded title and replaced `cursor_lower_bound()` with
  `find_best_match()` in message. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/rbtree.rs