Re: [PATCH 2/6] rust: binder: transmute transaction data
From: Alice Ryhl
Date: Tue May 26 2026 - 09:44:43 EST
On Tue, May 26, 2026 at 3:34 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
>
> On Tue, May 26, 2026 at 8:33 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> >
> > On Fri, May 22, 2026 at 07:12:47PM +0200, Tamir Duberstein wrote:
> > > `BinderTransactionData` is a transparent wrapper around
> > > `binder_transaction_data`. Use a transmute to view the transaction data in
> > > `BinderTransactionDataSecctx` through that wrapper, matching the safety
> > > argument at the conversion site and avoiding the raw pointer round trip.
> > >
> > > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>
> >
> > I think it is an anti-pattern to transmute references. Please keep the
> > raw pointer cast.
>
> Can you please elaborate? We already have this for kernel::io::Mmio:
>
> ```
> rust/kernel/io.rs- pub fn relaxed(&self) -> &RelaxedMmio<SIZE> {
> rust/kernel/io.rs- // SAFETY: `RelaxedMmio` is
> `#[repr(transparent)]` over `Mmio`, so `Mmio<SIZE>` and
> rust/kernel/io.rs- // `RelaxedMmio<SIZE>` have identical layout.
> rust/kernel/io.rs: unsafe { core::mem::transmute(self) }
> rust/kernel/io.rs- }
> ```
I also think that code is using the same anti-pattern.
Alice