Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] rust: id_pool: panic on find_unused_id with 0-capacity pool
--

commit 424a508011ab0d65530fe9badebd792ee11ae3f5
Author: Eliot Courtney <[email protected]>

rust: id_pool: do not round capacity up to BitmapVec::MAX_INLINE_LEN

This patch modifies IdPool::with_capacity to no longer round up the initial
capacity to BitmapVec::MAX_INLINE_LEN, allowing for a capacity of 0. It also
adjusts grow_request to ensure that a 0-capacity pool grows to at least
BitmapVec::MAX_INLINE_LEN instead of remaining 0.

> diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs
> index 06a4c71c4c6c9..4f329249df9d0 100644
> --- a/rust/kernel/id_pool.rs
> +++ b/rust/kernel/id_pool.rs
> @@ -112,13 +112,8 @@ pub fn new() -> Self {
>      }
>  
>      /// Constructs a new [`IdPool`] with space for a specific number of bits.
> -    ///
> -    /// A capacity below [`MAX_INLINE_LEN`] is adjusted to 
> [`MAX_INLINE_LEN`].
> -    ///
> -    /// [`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);
>          let map = BitmapVec::new(num_ids, flags)?;
>          Ok(Self { map })
>      }

[Severity: High]
Can allowing a capacity of 0 here introduce a regression where finding unused
IDs triggers a kernel panic?

If a user initializes a 0-capacity pool and calls find_unused_id() or
reserve_ids(), the offset is passed directly to the underlying Bitmap
functions.

For example, in IdPool::find_unused_id():

rust/kernel/id_pool.rs:IdPool::find_unused_id() {
    ...
    Some(UnusedId {
        id: self.map.next_zero_bit(offset)?,
        pool: self,
    })
    ...
}

The underlying Bitmap::next_zero_bit() function enforces a bounds check
via bitmap_assert!(start < self.len()).

For a 0-capacity pool with start=0, this evaluates to 0 < 0, triggering an
unconditional panic when the CONFIG_RUST_BITMAP_HARDENED configuration is
enabled.

Should we handle 0-capacity gracefully and return None to signal the need for
a grow_request() instead?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=8

Reply via email to