From: <rs@ti.com>
To: <robertcnelson@gmail.com>, <ayush@beagleboard.org>,
<Erik.Welsh@octavosystems.com>, <anshuld@ti.com>, <bb@ti.com>,
<trini@konsulko.com>, <afd@ti.com>, <xypron.glpk@gmx.de>,
<ilias.apalodimas@linaro.org>
Cc: <u-boot@lists.denx.de>
Subject: [PATCHv4 5/6] efi_mem_sort: use list_for_each_entry_safe instead
Date: Mon, 20 Apr 2026 14:25:19 -0500 [thread overview]
Message-ID: <20260420192520.1444749-6-rs@ti.com> (raw)
In-Reply-To: <20260420192520.1444749-1-rs@ti.com>
From: Randolph Sapp <rs@ti.com>
Use list_for_each_entry_safe and comparisons against the current and
next efi_mem_desc. This reduces the computation required for merging
regions, prevents unnecessary additional iterations of the list, and
requires less temporary values.
Signed-off-by: Randolph Sapp <rs@ti.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
lib/efi_loader/efi_memory.c | 47 +++++++++++++------------------------
1 file changed, 16 insertions(+), 31 deletions(-)
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index b77c2f980cc..046a2bb4641 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -128,44 +128,29 @@ static uint64_t desc_get_end(struct efi_mem_desc *desc)
*/
static void efi_mem_sort(void)
{
- struct efi_mem_list *lmem;
- struct efi_mem_list *prevmem = NULL;
- bool merge_again = true;
+ struct efi_mem_list *curmem, *nextmem = NULL;
list_sort(NULL, &efi_mem, efi_mem_cmp);
/* Now merge entries that can be merged */
- while (merge_again) {
- merge_again = false;
- list_for_each_entry(lmem, &efi_mem, link) {
- struct efi_mem_desc *prev;
- struct efi_mem_desc *cur;
- uint64_t pages;
+ list_for_each_entry_safe(curmem, nextmem, &efi_mem, link) {
+ struct efi_mem_desc *cur;
+ struct efi_mem_desc *next;
- if (!prevmem) {
- prevmem = lmem;
- continue;
- }
+ /* Exit when we've got nothing to compare with */
+ if (&nextmem->link == &efi_mem)
+ break;
- cur = &lmem->desc;
- prev = &prevmem->desc;
-
- if ((desc_get_end(cur) == prev->physical_start) &&
- (prev->type == cur->type) &&
- (prev->attribute == cur->attribute)) {
- /* There is an existing map before, reuse it */
- pages = cur->num_pages;
- prev->num_pages += pages;
- prev->physical_start -= pages << EFI_PAGE_SHIFT;
- prev->virtual_start -= pages << EFI_PAGE_SHIFT;
- list_del(&lmem->link);
- free(lmem);
-
- merge_again = true;
- break;
- }
+ cur = &curmem->desc;
+ next = &nextmem->desc;
- prevmem = lmem;
+ if ((cur->physical_start == desc_get_end(next)) &&
+ (cur->type == next->type) &&
+ (cur->attribute == next->attribute)) {
+ /* There is another similar map coming up, reuse it */
+ next->num_pages += cur->num_pages;
+ list_del(&curmem->link);
+ free(curmem);
}
}
}
--
2.53.0
next prev parent reply other threads:[~2026-04-20 19:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 19:25 [PATCHv4 0/6] various memory related fixups rs
2026-04-20 19:25 ` [PATCHv4 1/6] lmb: allocation flags macro documentation rs
2026-04-20 19:25 ` [PATCHv4 2/6] boot_fdt_add_mem_rsv_regions: free old dtb reservations rs
2026-04-20 19:25 ` [PATCHv4 3/6] efi_dt_fixup: use fdtdec_get_bool rs
2026-04-20 19:25 ` [PATCHv4 4/6] efi_selftest_memory: check for duplicates first rs
2026-04-20 19:25 ` rs [this message]
2026-04-20 19:25 ` [PATCHv4 6/6] memory: reserve from start_addr_sp to initial_relocaddr rs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420192520.1444749-6-rs@ti.com \
--to=rs@ti.com \
--cc=Erik.Welsh@octavosystems.com \
--cc=afd@ti.com \
--cc=anshuld@ti.com \
--cc=ayush@beagleboard.org \
--cc=bb@ti.com \
--cc=ilias.apalodimas@linaro.org \
--cc=robertcnelson@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox