[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBDP0BJW9VAZ.5KRU4V4288R8@kernel.org>
Date: Wed, 16 Jul 2025 20:32:05 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Daniel Almeida" <daniel.almeida@...labora.com>
Cc: <abdiel.janulgue@...il.com>, <robin.murphy@....com>,
<a.hindborg@...nel.org>, <ojeda@...nel.org>, <alex.gaynor@...il.com>,
<boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
<lossin@...nel.org>, <aliceryhl@...gle.com>, <tmgross@...ch.edu>,
<bhelgaas@...gle.com>, <kwilczynski@...nel.org>,
<gregkh@...uxfoundation.org>, <rafael@...nel.org>,
<rust-for-linux@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/5] rust: dma: add DMA addressing capabilities
On Wed Jul 16, 2025 at 7:55 PM CEST, Danilo Krummrich wrote:
> On Wed Jul 16, 2025 at 7:32 PM CEST, Daniel Almeida wrote:
>> Hi Danilo,
>>
>>> + #[inline]
>>> + pub const fn new(n: usize) -> Result<Self> {
>>> + Ok(Self(match n {
>>> + 0 => 0,
>>> + 1..=64 => u64::MAX >> (64 - n),
>>> + _ => return Err(EINVAL),
>>> + }))
>>> + }
>>> +
>>
>> Isn’t this equivalent to genmask_u64(0..=n) ? See [0].
>
> Instead of the match this can use genmask_checked_u64() and convert the Option
> to a Result, once genmask is upstream.
>
>> You should also get a compile-time failure if n is out of bounds by default using
>> genmask.
>
> No, we can't use genmask_u64(), `n` is not guaranteed to be known at compile
> time, so we'd need to use genmask_checked_u64().
>
> Of course, we could have a separate DmaMask constructor, e.g. with a const
> generic -- not sure that's worth though.
On the other hand, it doesn't hurt. Guess I will add another constructor with a
const generic. :)
I also quickly tried genmask and I have a few questions:
(1) Why does genmask not use a const generic? I think this makes it more
obvious that it's only intended to be used from const context.
(2) Why is there no build_assert() when the range exceeds the number of bits
of the target type? I would expect genmask_u64(0..100) to fail.
(3) OOC, why did you choose u32 as argument type?
Powered by blists - more mailing lists