[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DC9TERXGKWSK.IYHN84FXHS6R@nvidia.com>
Date: Sat, 23 Aug 2025 21:44:20 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Danilo Krummrich" <dakr@...nel.org>, "Alice Ryhl"
<aliceryhl@...gle.com>
Cc: <akpm@...ux-foundation.org>, <ojeda@...nel.org>,
<alex.gaynor@...il.com>, <boqun.feng@...il.com>, <gary@...yguo.net>,
<bjorn3_gh@...tonmail.com>, <lossin@...nel.org>, <a.hindborg@...nel.org>,
<tmgross@...ch.edu>, <abdiel.janulgue@...il.com>, <jgg@...pe.ca>,
<lyude@...hat.com>, <robin.murphy@....com>, <daniel.almeida@...labora.com>,
<rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 3/5] rust: scatterlist: Add type-state abstraction
for sg_table
On Fri Aug 22, 2025 at 8:54 PM JST, Danilo Krummrich wrote:
> On 8/22/25 1:52 PM, Alice Ryhl wrote:
>> On Fri, Aug 22, 2025 at 01:48:47PM +0200, Danilo Krummrich wrote:
>>> On Fri Aug 22, 2025 at 1:44 PM CEST, Alice Ryhl wrote:
>>>>> +impl<P> Owned<P>
>>>>> +where
>>>>> + for<'a> P: page::AsPageIter<Iter<'a> = VmallocPageIter<'a>> + 'static,
>>>>> +{
>>>>> + fn new(
>>>>> + dev: &Device<Bound>,
>>>>> + mut pages: P,
>>>>> + dir: dma::DataDirection,
>>>>> + flags: alloc::Flags,
>>>>> + ) -> Result<impl PinInit<Self, Error> + '_> {
>>>>> + let page_iter = pages.page_iter();
>>>>> + let size = page_iter.size();
>>>>
>>>> Variable naming here is confusing. There's another variable called size
>>>> in an inner scope, and then afterwards in RawSGTable you use *this* size
>>>> variable again.
>>>
>>> I can change the size in the assignment block of max_segment to max_size, or do
>>> you have other suggestions?
>>
>> How about just this?
>>
>> let max_segment = {
>> // SAFETY: `dev.as_raw()` is a valid pointer to a `struct device`.
>> let max_segment = unsafe { bindings::dma_max_mapping_size(dev.as_raw()) };
>> if max_segment == 0 {
>> u32::MAX
>> } else {
>> u32::try_from(max_segment).unwrap_or(u32::MAX)
>> }
>> };
>
> Looks good, thanks!
Would this also work? It's a bit shorter.
// SAFETY: `dev.as_raw()` is a valid pointer to a `struct device`.
let max_segment = match unsafe { bindings::dma_max_mapping_size(dev.as_raw()) } {
0 => u32::MAX,
max_segment => u32::try_from(max_segment).unwrap_or(u32::MAX),
};
Powered by blists - more mailing lists