Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Low] The construction of `UnusedArea` is missing the required `// 
INVARIANT:` comment.
--

commit dec3af2ba5f37136507d9a42f30fab7e3072db7f
Author: Eliot Courtney <[email protected]>

rust: id_pool: add contiguous area allocation

This commit adds support for contiguous area allocation to the ID pool by
introducing a new UnusedArea type that follows the same pattern as UnusedId.

> diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs
> index 384753fe0e44a..b471bfd974875 100644
> --- a/rust/kernel/id_pool.rs
> +++ b/rust/kernel/id_pool.rs
[ ... ]
> @@ -240,6 +245,33 @@ pub fn find_unused_id(&mut self, offset: usize) -> 
> Option<UnusedId<'_>> {
>      pub fn release_id(&mut self, id: usize) {
>          self.map.clear_bit(id);
>      }
> +
> +    /// Finds a contiguous area of `count` unused IDs at or after `offset`.
> +    ///
> +    /// `align_mask` must be `0` (no alignment) or one less than a power of 
> two, in which case the
> +    /// start of the returned area is a multiple of that power of two.
> +    ///
> +    /// Returns an [`UnusedArea`] upon success, or [`None`] if no such area 
> could be found.
> +    #[inline]
> +    #[must_use]
> +    pub fn find_unused_area(
> +        &mut self,
> +        offset: usize,
> +        count: NonZero<usize>,
> +        align_mask: usize,
> +    ) -> Option<UnusedArea<'_>> {
> +        let start = self.map.next_zero_area(offset, count.get(), 
> align_mask)?;
> +        Some(UnusedArea {
> +            range: start..start + count.get(),
> +            pool: self,
> +        })

[Severity: Low]
This isn't a bug, but should this UnusedArea instantiation include an
// INVARIANT: comment?

The Rust subsystem guidelines state that when a struct with an # Invariants
documentation section is constructed, the code should have an // INVARIANT:
comment explaining why the invariants are satisfied.

UnusedArea defines the invariant range.start <= range.end <= pool.map.len().
Would it be appropriate to add a comment here detailing why the bounds
guaranteed by next_zero_area() satisfy this invariant?

> +    }

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

Reply via email to