Skip to contentSkip to conversation

binder: replace unsafe NewAllocation transmute with field move

PATCH In review Thorsten Blum 2 participants 2 messages Oct 8 – Oct 13 Android drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 binder: replace unsafe NewAllocation transmute with field move

NewAllocation does not implement Drop and success() can return its Allocation field directly. Also remove the now-unused transparent representation.

---
 drivers/android/binder/allocation.rs | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/android/binder/allocation.rs +3 -7
index 165cb797eb1e..be405f2596ae 100644
@@ -298,17 +298,13 @@ fn drop(&mut self) {
 /// A wrapper around `Allocation` that is being created.
 ///
 /// If the allocation is destroyed while wrapped in this wrapper, then the allocation will be
-/// considered to be part of a failed transaction. Successful transactions avoid that by calling
-/// `success`, which skips the destructor.
-#[repr(transparent)]
+/// considered to be part of a failed transaction. Successful transactions call `success` and
+/// store the returned `Allocation` in the new transaction.
 pub(crate) struct NewAllocation(pub(crate) Allocation);
 
 impl NewAllocation {
     pub(crate) fn success(self) -> Allocation {
-        // This skips the destructor.
-        //
-        // SAFETY: This type is `#[repr(transparent)]`, so the layout matches.
-        unsafe { core::mem::transmute(self) }
+        self.0
     }
 }
 
maintainer
#1 lore raw
Quoted 5 lines · Thorsten Blum

NewAllocation does not implement Drop and success() can return its Allocation field directly. Also remove the now-unused transparent representation.

The NewAllocation type implements Drop as of commit e2e4a4527d18 ("rust_binder: allocation: call trace_transaction_failed_buffer_release()").

See: https://patch.msgid.link/[email protected]

Alice