From: Miguel Cordero Pamphile <miguelcorderopamphile@gmail.com>
To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Burak Emir" <burak.emir@gmail.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Miguel Cordero Pamphile" <miguelcorderopamphile@gmail.com>,
"Georgios Androutsopoulos" <georgeandrout13@gmail.com>
Subject: [PATCH] rust: bitmap: document `next_bit()`/`next_zero_bit()` panics
Date: Tue, 6 Oct 2026 19:10:09 +0000 [thread overview]
Message-ID: <20261006191009.143707-1-miguelcorderopamphile@gmail.com> (raw)
`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
next reply other threads:[~2026-10-06 19:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 19:10 Miguel Cordero Pamphile [this message]
2026-10-06 20:18 ` Georgios Androutsopoulos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261006191009.143707-1-miguelcorderopamphile@gmail.com \
--to=miguelcorderopamphile@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=burak.emir@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=georgeandrout13@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®