Re: [PATCH -next v7 1/2] rust: clist: Add support to interface with C linked lists

From: Daniel Almeida

Date: Fri Feb 06 2026 - 16:23:15 EST




> On 6 Feb 2026, at 17:51, Joel Fernandes <joelagnelf@xxxxxxxxxx> wrote:
>
> Hi Daniel,
> Hope you do not mind me replying piecemeal as I can reply more quickly. Thank
> you for all the comments.
>
> On 2/6/2026 12:49 PM, Daniel Almeida wrote:
>>> +use crate::{
>>> + bindings,
>>> + types::Opaque, //
>>> +};
>>> +
>>> +use pin_init::PinInit;
>>> +
>>> +/// Wraps a `list_head` object for use in intrusive linked lists.
>>> +///
>>> +/// # Invariants
>>> +///
>>> +/// - [`CListHead`] represents an allocated and valid `list_head` structure.
>>> +/// - Once a [`CListHead`] is created in Rust, it will not be modified by non-Rust code.
>>> +/// - All `list_head` for individual items are not modified for the lifetime of [`CListHead`].
>>
>> Can you expand on the two points above?
>
> This is basically saying that a C `list_head` that is wrapped by a `CListHead`
> is read-only for the lifetime of `ClistHead`. modifying the pointers anymore.
> That is the invariant.
>
> Or did I miss something?
>
> --
> Joel Fernandes
>
>


Yeah, but my point being: is there a reason why the underlying list has to
remain read-only? Is this a safety requirement or an invariant that is established
by the code above?


— Daniel