From: Gregor Haas <gregorhaas1997@gmail.com>
To: qemu-devel@nongnu.org
Cc: philmd@linaro.org, richard.henderson@linaro.org,
Gregor Haas <gregorhaas1997@gmail.com>
Subject: [PATCH] hw/core/loader: allow loading larger ROMs
Date: Wed, 26 Jun 2024 19:02:07 -0700 [thread overview]
Message-ID: <20240627020207.630125-1-gregorhaas1997@gmail.com> (raw)
The read() syscall is not guaranteed to return all data from a file. The
default ROM loader implementation currently does not take this into account,
instead failing if all bytes are not read at once. This change wraps the
read() syscall in a do/while loop to ensure all bytes of the ROM are read.
Signed-off-by: Gregor Haas <gregorhaas1997@gmail.com>
---
hw/core/loader.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2f8105d7de..afa26dccb1 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -1075,7 +1075,7 @@ ssize_t rom_add_file(const char *file, const char *fw_dir,
{
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
Rom *rom;
- ssize_t rc;
+ ssize_t rc, sz = 0;
int fd = -1;
char devpath[100];
@@ -1116,12 +1116,15 @@ ssize_t rom_add_file(const char *file, const char *fw_dir,
rom->datasize = rom->romsize;
rom->data = g_malloc0(rom->datasize);
lseek(fd, 0, SEEK_SET);
- rc = read(fd, rom->data, rom->datasize);
- if (rc != rom->datasize) {
- fprintf(stderr, "rom: file %-20s: read error: rc=%zd (expected %zd)\n",
- rom->name, rc, rom->datasize);
- goto err;
- }
+ do {
+ rc = read(fd, &rom->data[sz], rom->datasize);
+ if (rc == -1) {
+ fprintf(stderr, "rom: file %-20s: read error: %s\n",
+ rom->name, strerror(errno));
+ goto err;
+ }
+ sz += rc;
+ } while (sz != rom->datasize);
close(fd);
rom_insert(rom);
if (rom->fw_file && fw_cfg) {
--
2.45.2
next reply other threads:[~2024-06-27 4:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 2:02 Gregor Haas [this message]
2024-06-27 6:11 ` [PATCH] hw/core/loader: allow loading larger ROMs Xingtao Yao (Fujitsu) via
2024-06-27 17:35 ` Gregor Haas
2024-06-28 0:44 ` Xingtao Yao (Fujitsu) via
2024-06-28 0:53 ` Gregor Haas
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=20240627020207.630125-1-gregorhaas1997@gmail.com \
--to=gregorhaas1997@gmail.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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;
as well as URLs for NNTP newsgroup(s).