Re: [PATCH 1/2] rust: bitmap: add MAX_LEN and NO_ALLOC_MAX_LEN constants

Danilo Krummrich
2025-10-20T14:18:32Z

On 10/20/25 3:33 PM, Alice Ryhl wrote:
> To avoid hard-coding these values in drivers, define constants for them
> that drivers can reference.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Yes, please! :)

Acked-by: Danilo Krummrich <dakr@kernel.org>

> @@ -238,11 +244,11 @@ pub fn new(nbits: usize, flags: Flags) -> Result<Self, AllocError> {
> nbits,
> });
> }
> - if nbits > i32::MAX.try_into().unwrap() {
> + if nbits > Self::MAX_LEN {
> return Err(AllocError);
> }
> let nbits_u32 = u32::try_from(nbits).unwrap();

Can we also get rid of this please? :)

> - // SAFETY: `BITS_PER_LONG < nbits` and `nbits <= i32::MAX`.
> + // SAFETY: `BITS_PER_LONG < nbits` and `nbits <= MAX_LEN`.
> let ptr = unsafe { bindings::bitmap_zalloc(nbits_u32, flags.as_raw()) };
> let ptr = NonNull::new(ptr).ok_or(AllocError)?;
> // INVARIANT: `ptr` returned by C `bitmap_zalloc` and `nbits` checked.