From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
"Claude Opus 4.6" <noreply@anthropic.com>
Subject: [PATCH] fixup! libfile: factor out zero-page resistant read_file as __read_full_anywhere
Date: Tue, 24 Feb 2026 12:01:07 +0100 [thread overview]
Message-ID: <20260224110110.2301531-1-a.fatoum@pengutronix.de> (raw)
libfile: fix error masking in __read_full_anywhere
When the second read_full() call fails with a negative error code,
the function returns now + error_code, which is a positive value
that looks like a successful short read. For example, 4096 + (-5)
returns 4091 instead of propagating the -EIO.
Check the return value of the second read_full separately.
Reported-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/libfile.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/libfile.c b/lib/libfile.c
index f6eeaebe4cd1..f5cea7b94998 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -807,7 +807,7 @@ int cache_file(const char *path, char **newpath)
*/
int __read_full_anywhere(int fd, void *buf, size_t size)
{
- ssize_t now = 0;
+ ssize_t nbytes = 0, now;
if (unlikely(zero_page_contains((ulong)buf))) {
void *tmp = malloc(PAGE_SIZE);
@@ -822,9 +822,12 @@ int __read_full_anywhere(int fd, void *buf, size_t size)
if (now <= 0)
return now;
+
+ nbytes += now;
}
- return now + read_full(fd, buf + now, size - now);
+ now = read_full(fd, buf + nbytes, size - nbytes);
+ return now < 0 ? now : now + nbytes;
}
#define BUFSIZ (PAGE_SIZE * 32)
--
2.47.3
reply other threads:[~2026-02-24 11:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260224110110.2301531-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
/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