Re: [PATCH v3 04/12] rust: xarray: add `XArrayState`
From: Andreas Hindborg
Date: Tue Feb 24 2026 - 09:33:52 EST
Tamir Duberstein <tamird@xxxxxxxxx> writes:
> On Mon, Feb 9, 2026 at 6:39 AM 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.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> ---
>> rust/bindings/bindings_helper.h | 1 +
>> rust/kernel/xarray.rs | 41 ++++++++++++++++++++++++++++++++++++++++-
>> 2 files changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
>> index a067038b4b422..58605c32e8102 100644
>> --- a/rust/bindings/bindings_helper.h
>> +++ b/rust/bindings/bindings_helper.h
>> @@ -117,6 +117,7 @@ const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT;
>>
>> const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC = XA_FLAGS_ALLOC;
>> const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC1 = XA_FLAGS_ALLOC1;
>> +const size_t RUST_CONST_HELPER_XAS_RESTART = (size_t)XAS_RESTART;
>
> Please add a comment to explain the cast.
How is this:
// `XAS_RESTART` is defined with type `struct xa_node *`. `bindgen`
// cannot generate pointer typed constants, so we cast to `size_t`.
Best regards,
Andreas Hindborg