[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aCZYcs6Aj-cz81qs@pollux>
Date: Thu, 15 May 2025 23:11:14 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: Abdiel Janulgue <abdiel.janulgue@...il.com>, lyude@...hat.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 <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Valentin Obst <kernel@...entinobst.de>,
open list <linux-kernel@...r.kernel.org>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>, airlied@...hat.com,
rust-for-linux@...r.kernel.org,
"open list:DMA MAPPING HELPERS" <iommu@...ts.linux.dev>,
Petr Tesarik <petr@...arici.cz>,
Andrew Morton <akpm@...ux-foundation.org>,
Herbert Xu <herbert@...dor.apana.org.au>,
Sui Jingfeng <sui.jingfeng@...ux.dev>,
Randy Dunlap <rdunlap@...radead.org>,
Michael Kelley <mhklinux@...look.com>
Subject: Re: [RFC PATCH 1/2] rust: add initial scatterlist bindings
On Mon, May 12, 2025 at 08:39:36AM -0300, Daniel Almeida wrote:
> > On 12 May 2025, at 06:53, Abdiel Janulgue <abdiel.janulgue@...il.com> wrote:
> > +impl SGEntry {
> > + /// Convert a raw `struct scatterlist *` to a `&'a SGEntry`.
> > + ///
> > + /// # Safety
> > + ///
> > + /// Callers must ensure that the `struct scatterlist` pointed to by `ptr` is valid for the lifetime
> > + /// of the returned reference.
> > + pub unsafe fn as_ref<'a>(ptr: *mut bindings::scatterlist) -> &'a Self {
> > + // SAFETY: The pointer is valid and guaranteed by the safety requirements of the function.
> > + unsafe { &*ptr.cast() }
> > + }
>
> Hmm, this name is not good. When people see as_ref() they will think of the
> standard library where it is used to convert from &T to &U. This is not what is
> happening here. Same in other places where as_ref() is used in this patch.
as_ref() is fine, we use this exact way commonly in the kernel, e.g. for Device,
GlobalLockedBy, Cpumask and for various DRM types.
Rust std does the same, e.g. in [1].
I think I also asked for this in your Resource patch for consistency, where you
call this from_ptr() instead.
[1] https://doc.rust-lang.org/std/ptr/struct.NonNull.html#method.as_ref
Powered by blists - more mailing lists