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 <d...@axtens.net>

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

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to