summaryrefslogtreecommitdiff
path: root/drivers/android
diff options
context:
space:
mode:
authorVitaly Wool <vitaly.wool@konsulko.se>2025-10-14 14:33:39 +0200
committerMiguel Ojeda <ojeda@kernel.org>2025-11-16 21:56:57 +0100
commitf56b131723826dfdbf829d014591d831d649ae4a (patch)
treeb5d65dacadb43306e40412cf474ed3d37fc38e17 /drivers/android
parent5935461b458463ee51aac8d95c25d7a5e1de8c4d (diff)
rust: rbtree: add immutable cursor
Sometimes we may need to iterate over, or find an element in a read only (or read mostly) red-black tree, and in that case we don't need a mutable reference to the tree, which we'll however have to take to be able to use the current (mutable) cursor implementation. This patch adds a simple immutable cursor implementation to RBTree, which enables us to use an immutable tree reference. The existing (fully featured) cursor implementation is renamed to CursorMut, while retaining its functionality. The only existing user of the [mutable] cursor for RBTrees (binder) is updated to match the changes. Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20251014123339.2492210-1-vitaly.wool@konsulko.se [ Applied `rustfmt`. Added intra-doc link. Fixed unclosed example. Fixed docs description. Fixed typo and other formatting nits. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'drivers/android')
-rw-r--r--drivers/android/binder/freeze.rs4
-rw-r--r--drivers/android/binder/process.rs2
-rw-r--r--drivers/android/binder/range_alloc/tree.rs2
3 files changed, 4 insertions, 4 deletions
diff --git a/drivers/android/binder/freeze.rs b/drivers/android/binder/freeze.rs
index e68c3c8bc55a..87bebef53d94 100644
--- a/drivers/android/binder/freeze.rs
+++ b/drivers/android/binder/freeze.rs
@@ -321,7 +321,7 @@ impl Process {
KVVec::with_capacity(8, GFP_KERNEL).unwrap_or_else(|_err| KVVec::new());
let mut inner = self.lock_with_nodes();
- let mut curr = inner.nodes.cursor_front();
+ let mut curr = inner.nodes.cursor_front_mut();
while let Some(cursor) = curr {
let (key, node) = cursor.current();
let key = *key;
@@ -335,7 +335,7 @@ impl Process {
// Find the node we were looking at and try again. If the set of nodes was changed,
// then just proceed to the next node. This is ok because we don't guarantee the
// inclusion of nodes that are added or removed in parallel with this operation.
- curr = inner.nodes.cursor_lower_bound(&key);
+ curr = inner.nodes.cursor_lower_bound_mut(&key);
continue;
}
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index d8111c990f21..c406f8b48d82 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -1293,7 +1293,7 @@ impl Process {
{
while let Some(node) = {
let mut lock = self.inner.lock();
- lock.nodes.cursor_front().map(|c| c.remove_current().1)
+ lock.nodes.cursor_front_mut().map(|c| c.remove_current().1)
} {
node.to_key_value().1.release();
}
diff --git a/drivers/android/binder/range_alloc/tree.rs b/drivers/android/binder/range_alloc/tree.rs
index 7b1a248fcb02..838fdd2b47ea 100644
--- a/drivers/android/binder/range_alloc/tree.rs
+++ b/drivers/android/binder/range_alloc/tree.rs
@@ -207,7 +207,7 @@ impl<T> TreeRangeAllocator<T> {
}
pub(crate) fn reservation_abort(&mut self, offset: usize) -> Result<FreedRange> {
- let mut cursor = self.tree.cursor_lower_bound(&offset).ok_or_else(|| {
+ let mut cursor = self.tree.cursor_lower_bound_mut(&offset).ok_or_else(|| {
pr_warn!(
"EINVAL from range_alloc.reservation_abort - offset: {}",
offset