grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/6] mm: clarify grub_real_malloc


From: Daniel Kiper
Subject: Re: [PATCH 2/6] mm: clarify grub_real_malloc
Date: Wed, 8 Dec 2021 16:28:45 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Thu, Nov 25, 2021 at 02:22:46AM +1100, Daniel Axtens wrote:
> When iterating through the singly linked list of free blocks,
> grub_real_malloc uses p and q for the current and previous blocks
> respectively. This isn't super clear, so swap to using prev and cur.
>
> This makes another quirk more obvious. The comment at the top of
> grub_real_malloc might lead you to believe that the function will
> allocate from *first if there is space in that block.
>
> It actually doesn't do that, and it can't do that with the current
> data structures. If we used up all of *first, we would need to change
> the ->next of the previous block to point to *first->next, but we
> can't do that because it's a singly linked list and we don't have
> access to *first's previous block.
>
> What grub_real_malloc actually does is set *first to the initial
> previous block, and *first->next is the block we try to allocate
> from. That allows us to keep all the data structures consistent.
>
> Document that.
>
> Signed-off-by: Daniel Axtens <dja@axtens.net>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]