Skip to contentSkip to conversation

rust: id_pool: document panics in `find_unused_id` and `release_id`

PATCH Superseded Georgios Androutsopoulos 2 participants 2 messages Aug 29 – Aug 31

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 rust/kernel/id_pool.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
rust/kernel/id_pool.rs +14 -1
index 384753fe0..ae6960d7f 100644
@@ -224,7 +224,13 @@ pub fn grow(&mut self, mut resizer: PoolResizer) {
     /// 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
+    /// in 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 @@ pub fn find_unused_id(&mut self, offset: usize) -> Option<UnusedId<'_>> {
     }
 
     /// Releases an ID.
+    ///
+    /// The `id` must be in 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);

base-commit: 73e3f0710014fe6d4ed98cfc02292f6121db7558

Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Georgios Androutsopoulos

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.

One small nit below.

Quoted 9 lines
---
 rust/kernel/id_pool.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
rust/kernel/id_pool.rs +0 -0
index 384753fe0..ae6960d7f 100644

rust/kernel/id_pool.rs pub fn grow(&mut self, mut resizer: PoolResizer) { · line 228

Quoted 6 lines
rust/kernel/id_pool.rs +2 -1
@@ -224,7 +224,13 @@ pub fn grow(&mut self, mut resizer: PoolResizer) {
     /// 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
+    /// in bounds.

s/in/within maybe?