[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLggBd6s5MooGPfUaoarNF651BjTyBt+KcuJc0zdx5xg7cg@mail.gmail.com>
Date: Fri, 30 Jan 2026 11:26:44 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Eliot Courtney <ecourtney@...dia.com>
Cc: Danilo Krummrich <dakr@...nel.org>, Alexandre Courbot <acourbot@...dia.com>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
Abdiel Janulgue <abdiel.janulgue@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>,
Robin Murphy <robin.murphy@....com>, Andreas Hindborg <a.hindborg@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Trevor Gross <tmgross@...ch.edu>, nouveau@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
driver-core@...ts.linux.dev, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH 6/9] rust: dma: add dma_read! and dma_write! macros
On Fri, Jan 30, 2026 at 9:35 AM Eliot Courtney <ecourtney@...dia.com> wrote:
>
> Add dma_read! and dma_write! macros using the new infallible methods
> on CoherentArray.
>
> Signed-off-by: Eliot Courtney <ecourtney@...dia.com>
> ---
> rust/kernel/dma.rs | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 103 insertions(+)
>
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index e4bca7a18ac1..f3920f74583a 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -811,6 +811,24 @@ pub unsafe fn as_slice_mut<const OFFSET: usize, const COUNT: usize>(&mut self) -
> )
> };
> }
> +
> + /// Returns a pointer to an element from the region with bounds checking. `OFFSET` is in
> + /// units of `T`, not the number of bytes.
> + ///
> + /// Public but hidden since it should only be used from [`dma_read`] and [`dma_write`] macros.
> + #[doc(hidden)]
> + pub fn ptr_at<const OFFSET: usize>(&self) -> *mut T {
> + build_assert!(
> + OFFSET < N,
> + "Index out of bounds when accessing CoherentArray"
> + );
This build assert does not depend on runtime values, so it can be
written as a const block:
const { assert!(OFFSET < N, "Index out of bounds when accessing
CoherentArray"); }
Alice
Powered by blists - more mailing lists