From: Alice Ryhl Date: Tue, 25 Nov 2025 13:59:38 +0000 (+0000) Subject: rust: bitmap: add BitmapVec::new_inline() X-Git-Tag: v6.19-rc1~87^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0cf6512bbcf77afb6102f886fcd7fd48b7ae043;p=thirdparty%2Fkernel%2Fstable.git rust: bitmap: add BitmapVec::new_inline() This constructor is useful when you just want to create a BitmapVec without allocating but don't care how large it is. Acked-by: Yury Norov (NVIDIA) Reviewed-by: Burak Emir Reviewed-by: Danilo Krummrich Signed-off-by: Alice Ryhl Signed-off-by: Yury Norov (NVIDIA) --- diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs index 0705646c6251..83d7dea99137 100644 --- a/rust/kernel/bitmap.rs +++ b/rust/kernel/bitmap.rs @@ -230,6 +230,16 @@ impl BitmapVec { /// The maximum length that uses the inline representation. pub const MAX_INLINE_LEN: usize = usize::BITS as usize; + /// Construct a longest possible inline [`BitmapVec`]. + #[inline] + pub fn new_inline() -> Self { + // INVARIANT: `nbits <= MAX_INLINE_LEN`, so an inline bitmap is the right repr. + BitmapVec { + repr: BitmapRepr { bitmap: 0 }, + nbits: BitmapVec::MAX_INLINE_LEN, + } + } + /// Constructs a new [`BitmapVec`]. /// /// Fails with [`AllocError`] when the [`BitmapVec`] could not be allocated. This