Re: [PATCH] rust_binder: only remove a node from the tree if it is still there
From: Alice Ryhl
Date: Tue Nov 24 2026 - 07:13:36 EST
On Sun, Nov 22, 2026 at 08:13:22PM +0100, Nguyen Le Duy wrote:
> --- a/drivers/android/binder/node.rs
> +++ b/drivers/android/binder/node.rs
> @@ -636,7 +636,7 @@ impl Node {
> }
> if no_active_inc_refs && !weak {
> // Remove the node if there are no references to it.
> - guard.remove_node(self.ptr);
> + guard.remove_node(self);
> }
> drop(guard);
Nice catch, thanks for tracking this down!
Instead of still running `do_work_locked()` on a node that was already
deleted and checking the tree in `remove_node()`, perhaps `Node::do_work()`
should simply be a no-op if the node has been deleted?
If we track `is_deleted: bool` in `NodeInner` (set when `do_work_locked()`
removes the node from `ProcessInner::nodes`), then when the stale `Node`
work item later runs `Node::do_work()`, it can clear the `delivery_state`
flags and return `Ok(true)` early without entering `do_work_locked()` or
touching `nodes` at all (and `Node::cancel()` can skip re-queueing a
deleted node as well).
Since `do_work_locked()` only removes the node when `active_inc_refs == 0`
and `!weak`, any required `BR_RELEASE`/`BR_DECREFS` was already sent when
the node was deleted, and no new references can be acquired afterward.
What do you think?
Alice