* [PATCH 1/2] common: elf: use strdup_const for symmetry
@ 2026-01-05 8:33 Ahmad Fatoum
2026-01-05 8:33 ` [PATCH 2/2] common: elf: use memcmp for fixed-size comparison Ahmad Fatoum
2026-01-06 7:39 ` [PATCH 1/2] common: elf: use strdup_const for symmetry Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-01-05 8:33 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The elf->filename is free'd by free_const, but it's always allocated
with strdup. Change this to strdup_const to be able to avoid duplicating
string literals.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/elf.c b/common/elf.c
index c68ea0be3fa6..e8126c9b64e7 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -315,7 +315,7 @@ static struct elf_image *elf_check_init(const char *filename)
}
close(fd);
- elf->filename = strdup(filename);
+ elf->filename = strdup_const(filename);
if (!elf->filename) {
ret = -ENOMEM;
goto err_free_hdr_buf;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] common: elf: use memcmp for fixed-size comparison
2026-01-05 8:33 [PATCH 1/2] common: elf: use strdup_const for symmetry Ahmad Fatoum
@ 2026-01-05 8:33 ` Ahmad Fatoum
2026-01-06 7:39 ` [PATCH 1/2] common: elf: use strdup_const for symmetry Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-01-05 8:33 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
strncmp would only make sense if it were taking the size of buf as
argument, but it's taking the size of ELFMAG instead, which is a fixed 4
bytes. It's thus effectively equal to memcmp, so switch to using that
instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/elf.c b/common/elf.c
index e8126c9b64e7..18c541bf827e 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] common: elf: use strdup_const for symmetry
2026-01-05 8:33 [PATCH 1/2] common: elf: use strdup_const for symmetry Ahmad Fatoum
2026-01-05 8:33 ` [PATCH 2/2] common: elf: use memcmp for fixed-size comparison Ahmad Fatoum
@ 2026-01-06 7:39 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-01-06 7:39 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Mon, 05 Jan 2026 09:33:37 +0100, Ahmad Fatoum wrote:
> The elf->filename is free'd by free_const, but it's always allocated
> with strdup. Change this to strdup_const to be able to avoid duplicating
> string literals.
>
>
Applied, thanks!
[1/2] common: elf: use strdup_const for symmetry
https://git.pengutronix.de/cgit/barebox/commit/?id=2e47b5900193 (link may not be stable)
[2/2] common: elf: use memcmp for fixed-size comparison
https://git.pengutronix.de/cgit/barebox/commit/?id=3dc2cad1a7e7 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-06 7:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 8:33 [PATCH 1/2] common: elf: use strdup_const for symmetry Ahmad Fatoum
2026-01-05 8:33 ` [PATCH 2/2] common: elf: use memcmp for fixed-size comparison Ahmad Fatoum
2026-01-06 7:39 ` [PATCH 1/2] common: elf: use strdup_const for symmetry Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox