There is no good reason to allocate an IdPool with zero capacity.
Reflect this in IdPool::with_capacity.

Signed-off-by: Eliot Courtney <[email protected]>
---
 rust/kernel/id_pool.rs | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs
index 384753fe0e44..9494fde701ee 100644
--- a/rust/kernel/id_pool.rs
+++ b/rust/kernel/id_pool.rs
@@ -23,10 +23,13 @@
 /// Basic usage
 ///
 /// ```
-/// use kernel::alloc::AllocError;
-/// use kernel::id_pool::{IdPool, UnusedId};
+/// use kernel::{
+///     alloc::AllocError,
+///     id_pool::{IdPool, UnusedId},
+///     nz, //
+/// };
 ///
-/// let mut pool = IdPool::with_capacity(64, GFP_KERNEL)?;
+/// let mut pool = IdPool::with_capacity(nz!(64), GFP_KERNEL)?;
 /// for i in 0..64 {
 ///     assert_eq!(i, pool.find_unused_id(i).ok_or(ENOSPC)?.acquire());
 /// }
@@ -111,8 +114,8 @@ pub fn new() -> Self {
     ///
     /// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN
     #[inline]
-    pub fn with_capacity(num_ids: usize, flags: Flags) -> Result<Self, 
AllocError> {
-        let num_ids = usize::max(num_ids, BitmapVec::MAX_INLINE_LEN);
+    pub fn with_capacity(num_ids: NonZero<usize>, flags: Flags) -> 
Result<Self, AllocError> {
+        let num_ids = usize::max(num_ids.get(), BitmapVec::MAX_INLINE_LEN);
         let map = BitmapVec::new(num_ids, flags)?;
         Ok(Self { map })
     }
@@ -139,9 +142,10 @@ pub fn capacity(&self) -> usize {
     ///         IdPool,
     ///         ReallocRequest,
     ///     },
+    ///     nz, //
     /// };
     ///
-    /// let mut pool = IdPool::with_capacity(1024, GFP_KERNEL)?;
+    /// let mut pool = IdPool::with_capacity(nz!(1024), GFP_KERNEL)?;
     /// let alloc_request = pool.shrink_request().ok_or(AllocError)?;
     /// let resizer = alloc_request.realloc(GFP_KERNEL)?;
     /// pool.shrink(resizer);

-- 
2.55.0

Reply via email to