Skip to contentSkip to conversation

rust_binder: cancel deferred work items in thread exit

PATCH New Alice Ryhl 1 participant 1 message Sep 3

Subsystems (3)
lore
Share & tools
lore

Alice Ryhl

author maintainer
#0 lore raw

PATCH 1/1 rust_binder: cancel deferred work items in thread exit

If there are deferred work items on the thread todo list, then they are not cleaned up in the Thread::release() method. Thus, update the code to clean up the work items even if they are deferred.

This can happen if the thread dies while it has an active outgoing transaction.

Fixes eafedbc7c050 ("rust_binder: add Rust Binder driver")
---
 drivers/android/binder/thread.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/android/binder/thread.rs +7 -1
index 18a14aa8a835..24f7b5be1b0e 100644
@@ -686,6 +686,12 @@ pub(crate) fn push_return_work(&self, reply: u32) {
         self.inner.lock().push_return_work(reply);
     }
 
+    pub(crate) fn pop_work_even_if_deferred(&self) -> Option<DLArc<dyn DeliverToRead>> {
+        let mut thread_inner = self.inner.lock();
+        thread_inner.process_work_list = true;
+        thread_inner.pop_work()
+    }
+
     fn translate_object(
         &self,
         obj_index: usize,
@@ -1678,7 +1684,7 @@ pub(crate) fn release(self: &Arc<Self>) {
         self.unwind_transaction_stack();
 
         // Cancel all pending work items.
-        while let Ok(Some(work)) = self.get_work_local(false) {
+        while let Some(work) = self.pop_work_even_if_deferred() {
             work.into_arc().cancel();
         }
     }

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260903-binder-exit-get-work-7124b02f60e5

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>