Message ID | 20171201035023.13082-1-cyril.bur@au1.ibm.com |
---|---|
State | Accepted |
Headers | show |
Series | pflash: Respect write(2) return values | expand |
Cyril Bur <cyril.bur@au1.ibm.com> writes: > The write(2) system call returns the number of bytes written, this is > important since it is entitled to write less than what we requested. > Currently we ignore the return value and assume it wrote everything we > requested. While in practice this is likely to always be the case, it > isn't actually correct. > > This patch addresses this. > > Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> > --- > external/pflash/pflash.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) Merged to master as of 8e88ab0e66a201a1d786e7e95c98314bf4e806e7
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 381df24f..048dba3b 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -500,13 +500,18 @@ static int do_read_file(struct blocklevel_device *bl, const char *file, break; } rc = write(fd, file_buf, len); - if (rc < 0) { + /* + * zero isn't strictly an error. + * Treat it as such so we can be sure we'lre always + * making forward progress. + */ + if (rc <= 0) { perror("Error writing file"); break; } - start += len; - size -= len; - done += len; + start += rc; + size -= rc; + done += rc; progress_tick(done >> 8); } progress_end();
The write(2) system call returns the number of bytes written, this is important since it is entitled to write less than what we requested. Currently we ignore the return value and assume it wrote everything we requested. While in practice this is likely to always be the case, it isn't actually correct. This patch addresses this. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> --- external/pflash/pflash.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)