On Wed Feb 25, 2026 at 7:27 AM JST, Joel Fernandes wrote:
Add a new module `clist` for working with C's doubly circular linked
lists. Provide low-level iteration over list nodes.
Typed iteration over actual items is provided with a `clist_create`
macro to assist in creation of the `CList` type.
Cc: Nikola Djukic <redacted>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Acked-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
(with one small comment below)
quoted hunk ↗ jump to hunk
---
MAINTAINERS | 8 +
rust/helpers/helpers.c | 1 +
rust/helpers/list.c | 17 ++
rust/kernel/ffi/clist.rs | 338 +++++++++++++++++++++++++++++++++++++++
rust/kernel/ffi/mod.rs | 2 +
rust/kernel/lib.rs | 1 +
6 files changed, 367 insertions(+)
create mode 100644 rust/helpers/list.c
create mode 100644 rust/kernel/ffi/clist.rs
diff --git a/MAINTAINERS b/MAINTAINERS
index dc82a6bd1a61..0dc318c94c99 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23181,6 +23181,14 @@ T: git https://github.com/Rust-for-Linux/linux.git alloc-next
F: rust/kernel/alloc.rs
F: rust/kernel/alloc/
+RUST [FFI HELPER]
+M: Joel Fernandes <joelagnelf@nvidia.com> (CLIST)
+M: Alexandre Courbot <acourbot@nvidia.com> (CLIST)
+L: rust-for-linux@vger.kernel.org
+S: Maintained
+T: git https://github.com/Rust-for-Linux/linux.git ffi-next
+F: rust/kernel/ffi/
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
<snip>
+impl<'a, T, const OFFSET: usize> Iterator for CListIter<'a, T, OFFSET> {
+ type Item = &'a T;
+
+ #[inline]
+ fn next(&mut self) -> Option<Self::Item> {
+ let head = self.head_iter.next()?;
+
+ // Convert to item using OFFSET.
+ // SAFETY: `item_ptr` calculation from `OFFSET` (calculated using offset_of!)
`item_ptr` does not exist.