From: Artem Bityutskiy <dedekind@infradead.org>
To: Hai Zaar <haizaar@codefidence.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] nandwrite - handle situation when read returns less bytes the expected
Date: Tue, 16 Dec 2008 08:28:30 +0200 [thread overview]
Message-ID: <1229408910.4911.72.camel@sauron> (raw)
In-Reply-To: <76d9e2a30812140559y6ade25c0jf55fd8a7b299e83a@mail.gmail.com>
On Sun, 2008-12-14 at 15:59 +0200, Hai Zaar wrote:
> Good day!
> I've found a bug: nandwrite does not handle the situation when read
> syscall returns less bytes when expected. Instead of requesting more
> input, nandwrite just aborts with error.
> The bug is especially triggered when input comes from stdin[1] which
> is filled from remote host.
>
> [1] http://lists.infradead.org/pipermail/linux-mtd/2008-September/022913.html.
> BTW - is it going to be applied?
>
> P.S. I'm not on the list, so please CC me.
Your patch does not apply. It looks like it is not against the latest
mtd-utils. How about this patch?
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Date: Tue, 16 Dec 2008 10:02:16 +0200
Subject: [PATCH] nandwrite: correct data reading
The "read" syscall does not necessarily return all the requested
data, in which case the caller has to try again and read more.
Take this into account when reading input data.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
nandwrite.c | 31 +++++++++++++++++++++++--------
1 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/nandwrite.c b/nandwrite.c
index fc23e85..0b2a9ee 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -260,6 +260,7 @@ int main(int argc, char * const argv[])
int ret, readlen;
int oobinfochanged = 0;
struct nand_oobinfo old_oobinfo;
+ int readcnt = 0;
process_options(argc, argv);
@@ -477,6 +478,8 @@ int main(int argc, char * const argv[])
readlen = meminfo.writesize;
if (ifd != STDIN_FILENO) {
+ int tinycnt = 0;
+
if (pad && (imglen < readlen))
{
readlen = imglen;
@@ -484,11 +487,15 @@ int main(int argc, char * const argv[])
}
/* Read Page Data from input file */
- if ((cnt = read(ifd, writebuf, readlen)) != readlen) {
- if (cnt == 0) // EOF
+ while(tinycnt < readlen) {
+ cnt = read(ifd, writebuf + tinycnt, readlen - tinycnt);
+ if (cnt == 0) { // EOF
break;
- perror ("File I/O error on input file");
- goto closeall;
+ } else if (cnt < 0) {
+ perror ("File I/O error on input file");
+ goto closeall;
+ }
+ tinycnt += cnt;
}
} else {
int tinycnt = 0;
@@ -522,11 +529,19 @@ int main(int argc, char * const argv[])
}
if (writeoob) {
- /* Read OOB data from input file, exit on failure */
- if ((cnt = read(ifd, oobreadbuf, meminfo.oobsize)) != meminfo.oobsize) {
- perror ("File I/O error on input file");
- goto closeall;
+ int tinycnt = 0;
+
+ while(tinycnt < readlen) {
+ cnt = read(ifd, oobreadbuf + tinycnt, meminfo.oobsize - tinycnt);
+ if (cnt == 0) { // EOF
+ break;
+ } else if (cnt < 0) {
+ perror ("File I/O error on input file");
+ goto closeall;
+ }
+ tinycnt += cnt;
}
+
if (!noecc) {
int i, start, len;
/*
--
1.5.4.3
--
Best regards,
Artem Bityutskiy (Битюцкий Артём)
next prev parent reply other threads:[~2008-12-16 6:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-14 13:59 [PATCH] nandwrite - handle situation when read returns less bytes the expected Hai Zaar
2008-12-16 6:28 ` Artem Bityutskiy [this message]
2008-12-16 8:40 ` Hai Zaar
2008-12-16 10:18 ` Artem Bityutskiy
2008-12-24 14:48 ` Hai Zaar
2008-12-26 12:43 ` Artem Bityutskiy
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=1229408910.4911.72.camel@sauron \
--to=dedekind@infradead.org \
--cc=haizaar@codefidence.com \
--cc=linux-mtd@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