Re: [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics

From: Georgios Androutsopoulos

Date: Tue Oct 06 2026 - 16:18:46 EST


On Tue, Oct 6, 2026 at 3:10 PM Miguel Cordero Pamphile
<miguelcorderopamphile@xxxxxxxxx> wrote:
>
> `Bitmap::next_bit()` and `Bitmap::next_zero_bit()` panic when
> CONFIG_RUST_BITMAP_HARDENED is enabled and `start` is greater than or
> equal to `self.len()`, but their documentation did not mention it and
> stated instead that `None` would be returned for that input.
>
> Add the missing `# Panics` sections and clarify when `None` is returned,
> matching the existing documentation of `set_bit()` and friends.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1252
> Reported-by: Georgios Androutsopoulos <georgeandrout13@xxxxxxxxx>
> Signed-off-by: Miguel Cordero Pamphile <miguelcorderopamphile@xxxxxxxxx>
> ---
> rust/kernel/bitmap.rs | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> index b27e0ec80..5da8b12fb 100644
> --- a/rust/kernel/bitmap.rs
> +++ b/rust/kernel/bitmap.rs
> @@ -459,7 +459,13 @@ pub fn last_bit(&self) -> Option<usize> {
>
> /// Finds next set bit, starting from `start`.
> ///
> - /// Returns `None` if `start` is greater or equal to `self.nbits`.
> + /// If CONFIG_RUST_BITMAP_HARDENED is not enabled and `start` is greater than
> + /// or equal to `self.len()`, returns `None`.
> + ///
> + /// # Panics
> + ///
> + /// Panics if CONFIG_RUST_BITMAP_HARDENED is enabled and `start` is greater than
> + /// or equal to `self.len()`.
> #[inline]
> pub fn next_bit(&self, start: usize) -> Option<usize> {
> bitmap_assert!(
> @@ -479,7 +485,14 @@ pub fn next_bit(&self, start: usize) -> Option<usize> {
> }
>
> /// Finds next zero bit, starting from `start`.
> - /// Returns `None` if `start` is greater than or equal to `self.len()`.
> + ///
> + /// If CONFIG_RUST_BITMAP_HARDENED is not enabled and `start` is greater than
> + /// or equal to `self.len()`, returns `None`.
> + ///
> + /// # Panics
> + ///
> + /// Panics if CONFIG_RUST_BITMAP_HARDENED is enabled and `start` is greater than
> + /// or equal to `self.len()`.
> #[inline]
> pub fn next_zero_bit(&self, start: usize) -> Option<usize> {
> bitmap_assert!(
> --
> 2.50.1
>

This duplicates the patch I originally posted on August 27 and
subsequently sent as v3 on September 8. That patch was picked up into
bitmap-for-next earlier today, October 6.

Best,
Georgios