[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <B1BCB6C1-745B-4272-A0AB-8B8D1E444ECD@collabora.com>
Date: Wed, 16 Jul 2025 14:41:50 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Danilo Krummrich <dakr@...nel.org>
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 16 Jul 2025, at 14:32, Daniel Almeida <daniel.almeida@...labora.com> 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].
>
> You should also get a compile-time failure if n is out of bounds by default using
> genmask.
>
> — Daniel
>
> [0]: https://lore.kernel.org/rust-for-linux/20250714-topics-tyr-genmask2-v9-1-9e6422cbadb6@collabora.com/#r
Or genmask_u64(0..=n-1), if we disregard the previous off-by-one error
— Daniel
Powered by blists - more mailing lists