[PATCH 01/19] elf: Use memcmp to make suitable for PBL

Sascha Hauer s.hauer at pengutronix.de
Mon Jan 5 03:26:42 PST 2026


In preparation of adding ELF support to the PBL use memcmp rather than
strncmp for checking against the ELF magic. The other possibility would
be to add strncmp to the PBL, but for the sake of binary size use a
function that is already there.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/elf.c b/common/elf.c
index c68ea0be3fa668d988b27530644bbb77eb62ff48..692323c6beab2dd8aae9a9e874fb4980152a74e0 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -201,7 +201,7 @@ static int load_elf_image_segments(struct elf_image *elf)
 
 static int elf_check_image(struct elf_image *elf, void *buf)
 {
-	if (strncmp(buf, ELFMAG, SELFMAG)) {
+	if (memcmp(buf, ELFMAG, SELFMAG)) {
 		pr_err("ELF magic not found.\n");
 		return -EINVAL;
 	}

-- 
2.47.3




More information about the barebox mailing list