Re: [PATCH v2 2/5] rust: dma: add DMA addressing capabilities

From: Daniel Almeida
Date: Wed Jul 16 2025 - 13:33:46 EST


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@xxxxxxxxxxxxx/#r