Thread (23 messages) 23 messages, 4 authors, 2026-02-09

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

From: "Gary Guo" <gary@garyguo.net>
Date: 2026-02-06 20:51:19
Also in: amd-gfx, dri-devel, intel-gfx, intel-xe, linux-doc, linux-fbdev, lkml, nouveau

On Fri Feb 6, 2026 at 8:46 PM GMT, Joel Fernandes wrote:
On 2/6/2026 12:49 PM, Daniel Almeida wrote:
quoted
quoted
+#[repr(transparent)]
+pub(crate) struct CList<T, const OFFSET: usize>(CListHead, PhantomData<T>);
+
+impl<T, const OFFSET: usize> CList<T, OFFSET> {
+    /// Create a typed [`CList`] reference from a raw sentinel `list_head` pointer.
+    ///
+    /// # Safety
+    ///
+    /// - `ptr` must be a valid pointer to an allocated and initialized `list_head` structure
+    ///   representing a list sentinel.
+    /// - `ptr` must remain valid and unmodified for the lifetime `'a`.
+    /// - The list must contain items where the `list_head` field is at byte offset `OFFSET`.
+    /// - `T` must be `#[repr(transparent)]` over the C struct.
+    #[inline]
+    pub(crate) unsafe fn from_raw<'a>(ptr: *mut bindings::list_head) -> &'a Self {
+        // SAFETY:
+        // - [`CList`] has same layout as [`CListHead`] due to repr(transparent).
+        // - Caller guarantees `ptr` is a valid, sentinel `list_head` object.
+        unsafe { &*ptr.cast() }
+    }
+
+    /// Check if the list is empty.
+    #[inline]
+    #[expect(dead_code)]
+    pub(crate) fn is_empty(&self) -> bool {
Why can’t this be pub?
I believe this was suggested by Gary. See the other thread where we are
discussing it (with Gary and Danilo) and let us discuss there.
I suggested the module to be `pub(crate)`. For the individual item it is not
necessary if the module itself already have limited visibility.

Best,
Gary
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help