lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBDO8FVL9NKE.201JEW4MRHS6F@kernel.org>
Date: Wed, 16 Jul 2025 19:55:40 +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: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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ