summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorGeorgios Androutsopoulos <georgeandrout13@gmail.com>2026-09-08 16:31:57 -0400
committerYury Norov <ynorov@nvidia.com>2026-10-06 12:15:40 -0400
commit842c5beca0b369bb143b86d6ae63dbcd7c5f0988 (patch)
treee258fb52a1599c4b2647fbcada875fcbd0e45693 /rust/kernel
parent452a6d5b5e0556848a8c28428c8f86874ea4ee02 (diff)
rust: id_pool: document panics in `find_unused_id` and `release_id`
`find_unused_id()` calls `Bitmap::next_zero_bit()` and `release_id()` calls `Bitmap::clear_bit()`, both of which panic when `CONFIG_RUST_BITMAP_HARDENED` is enabled and the index is out of bounds. Neither `IdPool` method documents this. Add the missing `# Panics` sections and state the bounds requirement on `offset` and `id`. Fixes: 2cdae413cd3e ("rust: add dynamic ID pool abstraction for bitmap") Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Georgios Androutsopoulos <georgeandrout13@gmail.com> Signed-off-by: Yury Norov <ynorov@nvidia.com>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/id_pool.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs
index 384753fe0e44..c8b346554802 100644
--- a/rust/kernel/id_pool.rs
+++ b/rust/kernel/id_pool.rs
@@ -224,7 +224,13 @@ impl IdPool {
/// Finds an unused ID in the bitmap.
///
/// Upon success, returns its index. Otherwise, returns [`None`]
- /// to indicate that a [`Self::grow_request`] is needed.
+ /// to indicate that a [`Self::grow_request`] is needed. `offset` must be
+ /// within bounds.
+ ///
+ /// # Panics
+ ///
+ /// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `offset` is out
+ /// of bounds.
#[inline]
#[must_use]
pub fn find_unused_id(&mut self, offset: usize) -> Option<UnusedId<'_>> {
@@ -236,6 +242,13 @@ impl IdPool {
}
/// Releases an ID.
+ ///
+ /// The `id` must be within bounds.
+ ///
+ /// # Panics
+ ///
+ /// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `id` is out of
+ /// bounds.
#[inline]
pub fn release_id(&mut self, id: usize) {
self.map.clear_bit(id);