Re: [PATCH 1/2] rust: device: remove unused ref-to-ref transmute

From: Tamir Duberstein

Date: Sat May 30 2026 - 07:19:00 EST


On Sat, May 30, 2026 at 7:07 AM Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> On Tue May 26, 2026 at 3:39 PM BST, Tamir Duberstein wrote:
> > The Ok return value of `read_array_from_fwnode_property` requires a
> > reference-to-reference transmute to construct but is never read, thus
> > remove it.
> >
> > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>
> > ---
> > rust/kernel/device/property.rs | 42 +++++++++++++++++-------------------------
> > 1 file changed, 17 insertions(+), 25 deletions(-)
> >
> > diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
> > index 5aead835fbbc..87be2784f7a7 100644
> > --- a/rust/kernel/device/property.rs
> > +++ b/rust/kernel/device/property.rs
> > @@ -136,18 +136,15 @@ pub fn property_read_array_vec<'fwnode, 'name, T: PropertyInt>(
> > let mut val: KVec<T> = KVec::with_capacity(len, GFP_KERNEL)?;
> >
> > let res = T::read_array_from_fwnode_property(self, name, val.spare_capacity_mut());
> > - let res = match res {
> > - Ok(_) => {
> > - // SAFETY:
> > - // - `len` is equal to `val.capacity - val.len`, because
> > - // `val.capacity` is `len` and `val.len` is zero.
> > - // - All elements within the interval [`0`, `len`) were initialized
> > - // by `read_array_from_fwnode_property`.
> > - unsafe { val.inc_len(len) }
> > - Ok(val)
> > - }
> > - Err(e) => Err(e),
> > - };
> > + let res = res.map(|()| {
> > + // SAFETY:
> > + // - `len` is equal to `val.capacity - val.len`, because
> > + // `val.capacity` is `len` and `val.len` is zero.
> > + // - All elements within the interval [`0`, `len`) were initialized
> > + // by `read_array_from_fwnode_property`.
> > + unsafe { val.inc_len(len) }
> > + val
> > + });
> > Ok(PropertyGuard {
> > inner: res,
> > fwnode: self,
> > @@ -474,12 +471,12 @@ fn read_from_fwnode_property(fwnode: &FwNode, name: &CStr) -> Result<Self> {
> > /// It must be public, because it appears in the signatures of other public
> > /// functions, but its methods shouldn't be used outside the kernel crate.
> > pub trait PropertyInt: Copy + Sealed {
> > - /// Reads a property array.
> > - fn read_array_from_fwnode_property<'a>(
> > + /// Reads a property array into `out`.
> > + fn read_array_from_fwnode_property(
> > fwnode: &FwNode,
> > name: &CStr,
> > - out: &'a mut [MaybeUninit<Self>],
> > - ) -> Result<&'a mut [Self]>;
> > + out: &mut [MaybeUninit<Self>],
> > + ) -> Result;
>
> I think the old signature is quite reasonable. You provide storage and the
> buffer is filled and that the return value is the proof of initialization.
>
> If you're concerned with `transmute` it should just be replaced with
> `assume_init_mut()`.

The signature is reasonable, but it is dead code. This is a private
function; I see no benefit in keeping dead code around. If it is
needed in the future, it can be easily restored.