From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] common: elf: rename elf_section misnomer to elf_segment
Date: Mon,  3 Nov 2025 08:45:08 +0100	[thread overview]
Message-ID: <20251103074509.302260-1-a.fatoum@barebox.org> (raw)
An elf section is needed for linking, the segment is needed for loading.
We only handle statically linked ELF files currently in barebox, so we
do not look at the sections at all.
Replace the misleading struct elf_section with the correct naming:
elf_segment.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/elf.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/common/elf.c b/common/elf.c
index 8578892366c3..c68ea0be3fa6 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -14,7 +14,7 @@
 #include <linux/fs.h>
 #include <linux/list_sort.h>
 
-struct elf_section {
+struct elf_segment {
 	struct list_head list;
 	struct resource *r;
 	void *phdr;
@@ -26,16 +26,16 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,
 {
 	struct list_head *list = &elf->list;
 	struct resource *r_new;
-	struct elf_section *r;
+	struct elf_segment *r;
 
 	r = calloc(1, sizeof(*r));
 	if (!r)
 		return -ENOMEM;
 
-	r_new = request_sdram_region("elf_section", start, size,
+	r_new = request_sdram_region("elf_segment", start, size,
 				     MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 	if (!r_new) {
-		r_new = request_iomem_region("elf_section", start, size);
+		r_new = request_iomem_region("elf_segment", start, size);
 		if (!r_new) {
 			pr_err("Failed to request region: %pa %pa\n", &start, &size);
 			return -EINVAL;
@@ -53,7 +53,7 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,
 static void elf_release_regions(struct elf_image *elf)
 {
 	struct list_head *list = &elf->list;
-	struct elf_section *r, *r_tmp;
+	struct elf_segment *r, *r_tmp;
 
 	list_for_each_entry_safe(r, r_tmp, list, list) {
 		if (r->is_iomem_region)
@@ -92,16 +92,16 @@ static int request_elf_segment(struct elf_image *elf, void *phdr)
 	return 0;
 }
 
-static int elf_section_cmp(void *priv, struct list_head *a, struct list_head *b)
+static int elf_segment_cmp(void *priv, struct list_head *a, struct list_head *b)
 {
 	struct elf_image *elf = priv;
-	struct elf_section *elf_a, *elf_b;
+	struct elf_segment *elf_a, *elf_b;
 
 	if (a == b)
 		return 0;
 
-	elf_a = list_entry(a, struct elf_section, list);
-	elf_b = list_entry(b, struct elf_section, list);
+	elf_a = list_entry(a, struct elf_segment, list);
+	elf_b = list_entry(b, struct elf_segment, list);
 
 	return elf_phdr_p_offset(elf, elf_a->phdr) >
 	       elf_phdr_p_offset(elf, elf_b->phdr);
@@ -112,7 +112,7 @@ static int load_elf_to_memory(struct elf_image *elf)
 	void *dst;
 	int ret = 0, fd = -1;
 	u64 p_filesz, p_memsz, p_offset;
-	struct elf_section *r;
+	struct elf_segment *r;
 	struct list_head *list = &elf->list;
 
 	if (elf->filename) {
@@ -185,7 +185,7 @@ static int load_elf_image_segments(struct elf_image *elf)
 	 * Sort the list to avoid doing backward lseek while loading the elf
 	 * segments from file to memory(some filesystems don't support it)
 	 */
-	list_sort(elf, &elf->list, elf_section_cmp);
+	list_sort(elf, &elf->list, elf_segment_cmp);
 
 	ret = load_elf_to_memory(elf);
 	if (ret)
-- 
2.47.3
next             reply	other threads:[~2025-11-03  7:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03  7:45 Ahmad Fatoum [this message]
2025-11-03  8:42 ` Sascha Hauer
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=20251103074509.302260-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /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