mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/2] pblimage: ls1028a: fix handling of short reads on
Date: Wed, 15 May 2024 08:07:58 +0200	[thread overview]
Message-ID: <20240515060758.3580734-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240515060758.3580734-1-a.fatoum@pengutronix.de>

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@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




  reply	other threads:[~2024-05-15  6:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  6:07 [PATCH master 1/2] list: fix CONFIG_DEBUG_LIST link failure in PBL Ahmad Fatoum
2024-05-15  6:07 ` Ahmad Fatoum [this message]
2024-05-16  7:16 ` Sascha Hauer
2024-05-17  6:02   ` Ahmad Fatoum
2024-05-21 11:04 ` 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=20240515060758.3580734-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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