Re: [PATCH v7 02/10] rust: bitmap: restrict bitmap length to at most i32::MAX
"Alexandre Courbot" <[email protected]>
| Newsgroups | dev.linux.lists.nova-gpu,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Mon Aug 17, 2026 at 4:04 PM JST, Eliot Courtney wrote: > It is currently possible to construct a non-`BitmapVec` backed > `Bitmap` using `Bitmap::from_raw` that is larger than `i32::MAX`, and > it is not part of the unsafe requirements. Restricting all bitmaps > (even non-`BitmapVec` backed ones) to a maximum size of `i32::MAX` > simplifies a few things and matches `BitmapVec::MAX_LEN`. Can we be more explicit (if possible in the doccomments as well) about what "a few things" is? IIUC we are doing this because some of the C APIs take an `int`, so we can just state that much. Note also (as a point to consider, not a review ask) that we could enforce this requirement in the type system if we made `nbits` a `Bounded<usize, 31>`. Currently `from_raw` and `from_raw_mut` are unsafe, so this becomes one more invariant for the caller to uphold, but would we have made them unsafe just for this if they weren't already?