[PATCH] rust: list: add SAFETY comment for container_of in ListItem::prepare_to_insert

From: Alex Smolya

Date: Sun Aug 16 2026 - 03:27:53 EST


Document the safety rationale for `container_of!` in
`ListItem::prepare_to_insert` when using `ListLinksSelfPtr`.

In the `ListLinksSelfPtr` implementation of `ListItem`,
`view_links(me)` delegates to `raw_get_list_links`, which yields a
pointer to the `inner` field of `ListLinksSelfPtr<Self, $num>`.
Therefore, `links_field` is guaranteed to point to that `inner` field,
making the `container_of!` calculation sound and in-bounds of the
allocation.

Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/351
Signed-off-by: Alex Smolya <alexsmolya@xxxxxxxxx>
---
rust/kernel/list/impl_list_item_mod.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/list/impl_list_item_mod.rs
b/rust/kernel/list/impl_list_item_mod.rs
index d84aedfdc..c2a1f77fb 100644
--- a/rust/kernel/list/impl_list_item_mod.rs
+++ b/rust/kernel/list/impl_list_item_mod.rs
@@ -276,7 +276,8 @@ unsafe fn prepare_to_insert(me: *const Self) ->
*mut $crate::list::ListLinks<$nu
// SAFETY: The caller promises that `me` points at a
valid value of type `Self`.
let links_field = unsafe { <Self as
$crate::list::ListItem<$num>>::view_links(me) };

- // SAFETY: TODO.
+ // SAFETY: `links_field` originates from
`view_links(me)`, which returns a pointer
+ // to the `inner` field of a `ListLinksSelfPtr<Self,
$num>` inside `Self`.
let container = unsafe {
$crate::container_of!(
links_field,
$crate::list::ListLinksSelfPtr<Self, $num>, inner
--
2.55.0