binder: replace unsafe NewAllocation transmute with field move
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.
Signed-off-by Thorsten Blum <[email protected]>
--- drivers/android/binder/allocation.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/android/binder/allocation.rs +3 -7
@@ -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 } }
Alice Ryhl
maintainerQuoted 5 lines · Thorsten Blum
NewAllocation does not implement Drop and
success()can return its Allocation field directly. Also remove the now-unused transparent representation.Signed-off-by Thorsten Blum <[email protected]>
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