[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DG86CJXCM7DB.1A4F4JTMSS9ZZ@garyguo.net>
Date: Fri, 06 Feb 2026 20:51:15 +0000
From: "Gary Guo" <gary@...yguo.net>
To: "Joel Fernandes" <joelagnelf@...dia.com>, "Daniel Almeida"
<daniel.almeida@...labora.com>
Cc: <linux-kernel@...r.kernel.org>, "Maarten Lankhorst"
<maarten.lankhorst@...ux.intel.com>, "Maxime Ripard" <mripard@...nel.org>,
"Thomas Zimmermann" <tzimmermann@...e.de>, "David Airlie"
<airlied@...il.com>, "Simona Vetter" <simona@...ll.ch>, "Jonathan Corbet"
<corbet@....net>, "Alex Deucher" <alexander.deucher@....com>,
Christian König <christian.koenig@....com>, "Jani Nikula"
<jani.nikula@...ux.intel.com>, "Joonas Lahtinen"
<joonas.lahtinen@...ux.intel.com>, "Rodrigo Vivi" <rodrigo.vivi@...el.com>,
"Tvrtko Ursulin" <tursulin@...ulin.net>, "Huang Rui" <ray.huang@....com>,
"Matthew Auld" <matthew.auld@...el.com>, "Matthew Brost"
<matthew.brost@...el.com>, "Lucas De Marchi" <lucas.demarchi@...el.com>,
Thomas Hellström <thomas.hellstrom@...ux.intel.com>,
"Helge Deller" <deller@....de>, "Danilo Krummrich" <dakr@...nel.org>,
"Alice Ryhl" <aliceryhl@...gle.com>, "Miguel Ojeda" <ojeda@...nel.org>,
"Alex Gaynor" <alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>,
"Gary Guo" <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Trevor Gross" <tmgross@...ch.edu>,
"John Hubbard" <jhubbard@...dia.com>, "Alistair Popple"
<apopple@...dia.com>, "Timur Tabi" <ttabi@...dia.com>, "Edwin Peer"
<epeer@...dia.com>, "Alexandre Courbot" <acourbot@...dia.com>, "Andrea
Righi" <arighi@...dia.com>, "Andy Ritger" <aritger@...dia.com>, "Zhi Wang"
<zhiw@...dia.com>, "Balbir Singh" <balbirs@...dia.com>, "Philipp Stanner"
<phasta@...nel.org>, "Elle Rhumsaa" <elle@...thered-steel.dev>,
<joel@...lfernandes.org>, <nouveau@...ts.freedesktop.org>,
<dri-devel@...ts.freedesktop.org>, <rust-for-linux@...r.kernel.org>,
<linux-doc@...r.kernel.org>, <amd-gfx@...ts.freedesktop.org>,
<intel-gfx@...ts.freedesktop.org>, <intel-xe@...ts.freedesktop.org>,
<linux-fbdev@...r.kernel.org>
Subject: Re: [PATCH -next v7 1/2] rust: clist: Add support to interface with
C linked lists
On Fri Feb 6, 2026 at 8:46 PM GMT, Joel Fernandes wrote:
> On 2/6/2026 12:49 PM, Daniel Almeida wrote:
>>> +#[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
Powered by blists - more mailing lists