[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <D92V7PTBE3YP.2RFJGJS619NZN@nvidia.com>
Date: Thu, 10 Apr 2025 18:52:34 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Abdiel Janulgue" <abdiel.janulgue@...il.com>, <a.hindborg@...nel.org>,
<ojeda@...nel.org>
Cc: "Danilo Krummrich" <dakr@...nel.org>, "Daniel Almeida"
<daniel.almeida@...labora.com>, "Robin Murphy" <robin.murphy@....com>,
"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>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>, "open
list:DMA MAPPING HELPERS DEVICE DRIVER API [RUST]"
<rust-for-linux@...r.kernel.org>, "Marek Szyprowski"
<m.szyprowski@...sung.com>, "open list:DMA MAPPING HELPERS"
<iommu@...ts.linux.dev>, "open list" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 3/3] rust: dma: add as_slice/write functions for
CoherentAllocation
On Thu Apr 10, 2025 at 6:02 PM JST, Abdiel Janulgue wrote:
> Hi Alex,
>
> On 08/04/2025 06:08, Alexandre Courbot wrote:
>>> + }
>>> + // SAFETY:
>>> + // - The pointer is valid due to type invariant on `CoherentAllocation`
>>> + // and we've just checked that the range and index is within bounds.
>>> + // - `offset` can't overflow since it is smaller than `self.count` and we've checked
>>> + // that `self.count` won't overflow early in the constructor.
>>> + unsafe {
>>> + core::ptr::copy_nonoverlapping(src.as_ptr(), self.cpu_addr.add(offset), src.len())
>>> + };
>>
>> How about leveraging as_slice_mut() so this unsafe block can be removed?
>
> as_slice_mut is still unsafe, no? So we couldn't remove unsafe block still?
Ah, that's right. In that case it would at least factorize the bound
check and make the method a bit shorter, unless I missed something else.
Powered by blists - more mailing lists