]> git.ipfire.org Git - thirdparty/grub.git/commit
mm: Clarify grub_real_malloc()
authorDaniel Axtens <dja@axtens.net>
Wed, 24 Nov 2021 15:22:46 +0000 (02:22 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 23 Dec 2021 01:59:14 +0000 (02:59 +0100)
commit246ad6a44c281bb13486ddea0a26bb661db73106
tree447435bb7baa9d7ddaed10952fa617a51d9f915e
parenta6c5c52ccffd2674d43db25fb4baa9c528526aa0
mm: Clarify grub_real_malloc()

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>
grub-core/kern/mm.c