[PATCH master 2/2] pblimage: ls1028a: fix handling of short reads on
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue May 14 23:07:58 PDT 2024
Newer toolchains rightly complain:
scripts/pblimage.c:259:17: error: ignoring return value of ‘read’ declared
with attribute ‘warn_unused_result’ [-Werror=unused-result]
259 | read(in_fd, mem_buf + 0x1000, image_size);
In the ls1046a case, this doesn't happen, because pbl_fget is used,
which does a number of things:
- report warnings and exit on read errors
- fill buffer with 0xff on short reads
- increment pmem_buf and pbl_size by the number of bytes emitted
All of which, sound like a good idea for the ls1028a as well. Therefore,
initialize pmem_buf and pbl_size to the correct value and use pbl_fget.
This makes the code easier to follow through by making it explicit that
the image's payload is always given a 4K alignment, independent of the
size of the image header.
This change has only been build-tested.
Fixes: d5e5a65c2b64 ("pblimage: Add LS1028a support")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
scripts/pblimage.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index 610d93b36800..a3ed74836883 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -254,10 +254,16 @@ static void pbl_load_image(void)
buf32[3] = image_size;
buf32[4] = 0x80ff0000;
pbl_size += 20;
- pmem_buf += 20;
- read(in_fd, mem_buf + 0x1000, image_size);
- pbl_size = 0x1000 + image_size;
+ if (pbl_size > 0x1000) {
+ fprintf(stderr, "Header exceeded maximum size of 4K\n");
+ exit(EXIT_FAILURE);
+ }
+
+ pmem_buf = mem_buf + 0x1000;
+ pbl_size = 0x1000;
+
+ pbl_fget(image_size, in_fd);
} else {
exit(EXIT_FAILURE);
}
--
2.39.2
More information about the barebox
mailing list