On Thu Oct 30, 2025 at 8:06 PM CET, Joel Fernandes wrote:
> +    ///
> +    /// Returns an [`AllocatedBlocks`] structure that owns the allocated 
> blocks and automatically
> +    /// frees them when dropped. Allocation of `list_head` uses the `gfp` 
> flags passed.
> +    pub fn alloc_blocks(
> +        &self,
> +        start: usize,
> +        end: usize,
> +        size: usize,
> +        min_block_size: usize,
> +        flags: BuddyFlags,
> +        gfp: Flags,
> +    ) -> Result<AllocatedBlocks<'_>> {
> +        // Allocate list_head on the heap.
> +        let mut list_head = KBox::new(bindings::list_head::default(), gfp)?;
> +
> +        // SAFETY: list_head is valid and heap-allocated.
> +        unsafe {
> +            bindings::INIT_LIST_HEAD(&mut *list_head as *mut _);
> +        }

Not a full review, but a quick drive-by comment:

bindings::list_head has to be pinned in memory it should be

        let list_head = KBox::pin_init(Opaque::ffi_init(|slot: *mut 
bindings::list_head| {
            // SAFETY: `slot` is a valid pointer to uninitialized memory.
            unsafe { bindings::INIT_LIST_HEAD(slot) };
        }), gfp)?;

if you're doing it by hand, but as mentioned in a previous patch, I think it
would be nice to have a transparent wrapper type, CListHead, for this.

Reply via email to