Re: [PATCH v4 03/11] rust: xarray: add `XArrayState`

From: Tamir Duberstein

Date: Fri Jun 05 2026 - 11:22:47 EST


On Thu, 04 Jun 2026 21:58:09 +0200, Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> Add `XArrayState` as internal state for XArray iteration and entry
> operations. This struct wraps the C `xa_state` structure and holds a
> reference to a `Guard` to ensure exclusive access to the XArray for the
> lifetime of the state object.
>
> The `XAS_RESTART` constant is also exposed through the bindings helper
> to properly initialize the `xa_node` field.
>
> The struct and its constructor are marked with `#[expect(dead_code)]` as
> there are no users yet. We will remove this annotation in a later patch.

The review of this patch in v3 requested the next patch be absorbed into
it.

>
>
> diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
> index d54942aeb201..6d0d4905004a 100644
> --- a/rust/kernel/xarray.rs
> +++ b/rust/kernel/xarray.rs
> @@ -299,6 +302,67 @@ pub fn store(
> [ ... skip 17 lines ... ]
> +impl<'a, T: ForeignOwnable> GuardRef for &mut Guard<'a, T> {
> + type Value = T;
> + fn xa_ptr(&self) -> *mut bindings::xarray {
> + self.xa.xa.get()
> + }
> +}

I'm having a hard time understanding the need for this trait, and it is
not described in the commit message at all. How is this different than
using Deref? `&mut T` has a blanket `Deref<Target = T>` impl.

--
Tamir Duberstein <tamird@xxxxxxxxxx>