From d47caa0b2856a24122ee3b2a5fdee73b74a267c3 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 25 Jun 2025 09:42:34 +0000 Subject: [PATCH] ANDROID: rust_binder: reduce counts in NodeRef::absorb Rust Binder would in some cases avoid decrementing refcounts when it has multiple counts on the same node to avoid taking the lock unnecessarily. However, servicemanager relies on the exact value of the refcount to determine whether lazy services should be removed, so add logic to delete these duplicate refcounts. No need to schedule the node, since we never decrement any counts all the way to zero in this scenario. Bug: 427655909 Change-Id: I4383cadd7d9253e45aa542b7cbbab5db0094bd84 Signed-off-by: Alice Ryhl --- drivers/android/binder/node.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs index 18cc45ce6eeb..4e407e6a6c40 100644 --- a/drivers/android/binder/node.rs +++ b/drivers/android/binder/node.rs @@ -827,6 +827,22 @@ impl NodeRef { other.weak_count = 0; other.strong_node_count = 0; other.weak_node_count = 0; + + if self.strong_node_count >= 2 || self.weak_node_count >= 2 { + let mut guard = self.node.owner.inner.lock(); + let inner = self.node.inner.access_mut(&mut guard); + + if self.strong_node_count >= 2 { + inner.strong.count -= self.strong_node_count - 1; + self.strong_node_count = 1; + assert_ne!(inner.strong.count, 0); + } + if self.weak_node_count >= 2 { + inner.weak.count -= self.weak_node_count - 1; + self.weak_node_count = 1; + assert_ne!(inner.weak.count, 0); + } + } } pub(crate) fn get_count(&self) -> (usize, usize) {