* [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics
@ 2026-10-06 19:10 Miguel Cordero Pamphile
2026-10-06 20:18 ` Georgios Androutsopoulos
0 siblings, 1 reply; 2+ messages in thread
From: Miguel Cordero Pamphile @ 2026-10-06 19:10 UTC (permalink / raw)
To: rust-for-linux, linux-kernel
Cc: Alice Ryhl, Burak Emir, Yury Norov, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Miguel Cordero Pamphile,
Georgios Androutsopoulos
`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@gmail.com>
Signed-off-by: Miguel Cordero Pamphile <miguelcorderopamphile@gmail.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics
2026-10-06 19:10 [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics Miguel Cordero Pamphile
@ 2026-10-06 20:18 ` Georgios Androutsopoulos
0 siblings, 0 replies; 2+ messages in thread
From: Georgios Androutsopoulos @ 2026-10-06 20:18 UTC (permalink / raw)
To: Miguel Cordero Pamphile
Cc: rust-for-linux, linux-kernel, Alice Ryhl, Burak Emir, Yury Norov,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
On Tue, Oct 6, 2026 at 3:10 PM Miguel Cordero Pamphile
<miguelcorderopamphile@gmail.com> 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@gmail.com>
> Signed-off-by: Miguel Cordero Pamphile <miguelcorderopamphile@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-06 20:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-06 19:10 [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics Miguel Cordero Pamphile
2026-10-06 20:18 ` Georgios Androutsopoulos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®