From: Thibault Ferrante <thibaultferrante@gmail.com>
To: u-boot@lists.denx.de
Cc: wd@denx.de, joe.hershberger@ni.com, hws@denx.de,
alex.kiernan@gmail.com, lg@denx.de,
"Thibault Ferrante" <thibault.ferrante@gmail.com>,
"Martin Hundebøll" <martin@geanix.com>
Subject: [PATCH 1/1] tools: env: Handle shorter read calls
Date: Tue, 24 Aug 2021 17:29:50 +0200 [thread overview]
Message-ID: <20210824152950.919452-2-thibault.ferrante@gmail.com> (raw)
In-Reply-To: <20210824152950.919452-1-thibault.ferrante@gmail.com>
On some cases, the actual number of bytes read can be shorter
than what was requested. This can be handled gracefully by
taking this difference into account instead of exiting.
Signed-off-by: Thibault Ferrante <thibault.ferrante@gmail.com>
---
tools/env/fw_env.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 2a61a5d6f0..e39c39e23a 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -951,21 +951,23 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
DEVNAME(dev), strerror(errno));
return -1;
}
- if (rc != readlen) {
- fprintf(stderr,
- "Read error on %s: Attempted to read %zd bytes but got %d\n",
- DEVNAME(dev), readlen, rc);
- return -1;
- }
#ifdef DEBUG
fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n",
rc, (unsigned long long)blockstart + block_seek,
DEVNAME(dev));
#endif
- processed += readlen;
- readlen = min(blocklen, count - processed);
- block_seek = 0;
- blockstart += blocklen;
+ processed += rc;
+ if (rc != readlen) {
+ fprintf(stderr,
+ "Warning on %s: Attempted to read %zd bytes but got %d\n",
+ DEVNAME(dev), readlen, rc);
+ readlen -= rc;
+ block_seek += rc;
+ } else {
+ blockstart += blocklen;
+ readlen = min(blocklen, count - processed);
+ block_seek = 0;
+ }
}
return processed;
--
2.25.1
next prev parent reply other threads:[~2021-08-25 1:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-24 15:29 [PATCH 0/1] tools: env: Handle shorter read calls Thibault Ferrante
2021-08-24 15:29 ` Thibault Ferrante [this message]
2021-09-02 22:42 ` [PATCH 1/1] " Tom Rini
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=20210824152950.919452-2-thibault.ferrante@gmail.com \
--to=thibaultferrante@gmail.com \
--cc=alex.kiernan@gmail.com \
--cc=hws@denx.de \
--cc=joe.hershberger@ni.com \
--cc=lg@denx.de \
--cc=martin@geanix.com \
--cc=thibault.ferrante@gmail.com \
--cc=u-boot@lists.denx.de \
--cc=wd@denx.de \
/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